diff options
Diffstat (limited to 'api')
| -rw-r--r-- | api/Android.bp | 12 | ||||
| -rw-r--r-- | api/StubLibraries.bp | 123 | ||||
| -rw-r--r-- | api/coverage/tools/ExtractFlaggedApis.kt | 84 |
3 files changed, 172 insertions, 47 deletions
diff --git a/api/Android.bp b/api/Android.bp index 010a2a587057..3fa9c600741e 100644 --- a/api/Android.bp +++ b/api/Android.bp @@ -382,6 +382,18 @@ stubs_defaults { ], } +soong_config_module_type { + name: "non_updatable_exportable_droidstubs", + module_type: "droidstubs", + config_namespace: "ANDROID", + bool_variables: [ + "release_hidden_api_exportable_stubs", + ], + properties: [ + "dists", + ], +} + // We resolve dependencies on APIs in modules by depending on a prebuilt of the whole // platform (sdk_system_current_android). That prebuilt does not include module-lib APIs, // so use the prebuilt module-lib stubs for modules that export module-lib stubs that the diff --git a/api/StubLibraries.bp b/api/StubLibraries.bp index c1add03fa31a..1b1bc6b9afdb 100644 --- a/api/StubLibraries.bp +++ b/api/StubLibraries.bp @@ -27,7 +27,12 @@ // These modules provide source files for the stub libraries ///////////////////////////////////////////////////////////////////// -droidstubs { +soong_config_module_type_import { + from: "frameworks/base/api/Android.bp", + module_types: ["non_updatable_exportable_droidstubs"], +} + +non_updatable_exportable_droidstubs { name: "api-stubs-docs-non-updatable", defaults: [ "android-non-updatable-stubs-defaults", @@ -54,15 +59,35 @@ droidstubs { targets: ["sdk"], dir: "apistubs/android/public/api", dest: "android-non-updatable.txt", - tag: ".api.txt", }, { targets: ["sdk"], dir: "apistubs/android/public/api", dest: "android-non-updatable-removed.txt", - tag: ".removed-api.txt", }, ], + soong_config_variables: { + release_hidden_api_exportable_stubs: { + dists: [ + { + tag: ".exportable.api.txt", + }, + { + tag: ".exportable.removed-api.txt", + }, + ], + conditions_default: { + dists: [ + { + tag: ".api.txt", + }, + { + tag: ".removed-api.txt", + }, + ], + }, + }, + }, api_surface: "public", } @@ -86,7 +111,7 @@ module_libs = [ "\\)", ] -droidstubs { +non_updatable_exportable_droidstubs { name: "system-api-stubs-docs-non-updatable", defaults: [ "android-non-updatable-stubs-defaults", @@ -114,19 +139,39 @@ droidstubs { targets: ["sdk"], dir: "apistubs/android/system/api", dest: "android-non-updatable.txt", - tag: ".api.txt", }, { targets: ["sdk"], dir: "apistubs/android/system/api", dest: "android-non-updatable-removed.txt", - tag: ".removed-api.txt", }, ], + soong_config_variables: { + release_hidden_api_exportable_stubs: { + dists: [ + { + tag: ".exportable.api.txt", + }, + { + tag: ".exportable.removed-api.txt", + }, + ], + conditions_default: { + dists: [ + { + tag: ".api.txt", + }, + { + tag: ".removed-api.txt", + }, + ], + }, + }, + }, api_surface: "system", } -droidstubs { +non_updatable_exportable_droidstubs { name: "test-api-stubs-docs-non-updatable", defaults: [ "android-non-updatable-stubs-defaults", @@ -149,31 +194,61 @@ droidstubs { targets: ["sdk"], dir: "apistubs/android/test/api", dest: "android.txt", - tag: ".api.txt", }, { targets: ["sdk"], dir: "apistubs/android/test/api", dest: "removed.txt", - tag: ".removed-api.txt", }, { targets: ["sdk"], dir: "apistubs/android/test/api", dest: "android-non-updatable.txt", - tag: ".api.txt", }, { targets: ["sdk"], dir: "apistubs/android/test/api", dest: "android-non-updatable-removed.txt", - tag: ".removed-api.txt", }, ], + soong_config_variables: { + release_hidden_api_exportable_stubs: { + dists: [ + { + tag: ".exportable.api.txt", + }, + { + tag: ".exportable.removed-api.txt", + }, + { + tag: ".exportable.api.txt", + }, + { + tag: ".exportable.removed-api.txt", + }, + ], + conditions_default: { + dists: [ + { + tag: ".api.txt", + }, + { + tag: ".removed-api.txt", + }, + { + tag: ".api.txt", + }, + { + tag: ".removed-api.txt", + }, + ], + }, + }, + }, api_surface: "test", } -droidstubs { +non_updatable_exportable_droidstubs { name: "module-lib-api-stubs-docs-non-updatable", defaults: [ "android-non-updatable-stubs-defaults", @@ -201,15 +276,35 @@ droidstubs { targets: ["sdk"], dir: "apistubs/android/module-lib/api", dest: "android-non-updatable.txt", - tag: ".api.txt", }, { targets: ["sdk"], dir: "apistubs/android/module-lib/api", dest: "android-non-updatable-removed.txt", - tag: ".removed-api.txt", }, ], + soong_config_variables: { + release_hidden_api_exportable_stubs: { + dists: [ + { + tag: ".exportable.api.txt", + }, + { + tag: ".exportable.removed-api.txt", + }, + ], + conditions_default: { + dists: [ + { + tag: ".api.txt", + }, + { + tag: ".removed-api.txt", + }, + ], + }, + }, + }, api_surface: "module-lib", } diff --git a/api/coverage/tools/ExtractFlaggedApis.kt b/api/coverage/tools/ExtractFlaggedApis.kt index caa1929abd54..d5adfd09b994 100644 --- a/api/coverage/tools/ExtractFlaggedApis.kt +++ b/api/coverage/tools/ExtractFlaggedApis.kt @@ -16,51 +16,69 @@ package android.platform.coverage +import com.android.tools.metalava.model.ClassItem +import com.android.tools.metalava.model.MethodItem import com.android.tools.metalava.model.text.ApiFile import java.io.File import java.io.FileWriter /** Usage: extract-flagged-apis <api text file> <output .pb file> */ fun main(args: Array<String>) { - var cb = ApiFile.parseApi(listOf(File(args[0]))) - var builder = FlagApiMap.newBuilder() + val cb = ApiFile.parseApi(listOf(File(args[0]))) + val builder = FlagApiMap.newBuilder() for (pkg in cb.getPackages().packages) { - var packageName = pkg.qualifiedName() + val packageName = pkg.qualifiedName() pkg.allClasses() .filter { it.methods().size > 0 } .forEach { - for (method in it.methods()) { - val flagValue = - method.modifiers - .findAnnotation("android.annotation.FlaggedApi") - ?.findAttribute("value") - ?.value - ?.value() - if (flagValue != null && flagValue is String) { - var api = - JavaMethod.newBuilder() - .setPackageName(packageName) - .setClassName(it.fullName()) - .setMethodName(method.name()) - for (param in method.parameters()) { - api.addParameters(param.type().toTypeString()) - } - if (builder.containsFlagToApi(flagValue)) { - var updatedApis = - builder - .getFlagToApiOrThrow(flagValue) - .toBuilder() - .addJavaMethods(api) - .build() - builder.putFlagToApi(flagValue, updatedApis) - } else { - var apis = FlaggedApis.newBuilder().addJavaMethods(api).build() - builder.putFlagToApi(flagValue, apis) - } - } - } + extractFlaggedApisFromClass(it, it.methods(), packageName, builder) + extractFlaggedApisFromClass(it, it.constructors(), packageName, builder) } } val flagApiMap = builder.build() FileWriter(args[1]).use { it.write(flagApiMap.toString()) } } + +fun extractFlaggedApisFromClass( + classItem: ClassItem, + methods: List<MethodItem>, + packageName: String, + builder: FlagApiMap.Builder +) { + val classFlag = + classItem.modifiers + .findAnnotation("android.annotation.FlaggedApi") + ?.findAttribute("value") + ?.value + ?.value() as? String + for (method in methods) { + val methodFlag = + method.modifiers + .findAnnotation("android.annotation.FlaggedApi") + ?.findAttribute("value") + ?.value + ?.value() as? String + ?: classFlag + val api = + JavaMethod.newBuilder() + .setPackageName(packageName) + .setClassName(classItem.fullName()) + .setMethodName(method.name()) + for (param in method.parameters()) { + api.addParameters(param.type().toTypeString()) + } + if (methodFlag != null) { + addFlaggedApi(builder, api, methodFlag) + } + } +} + +fun addFlaggedApi(builder: FlagApiMap.Builder, api: JavaMethod.Builder, flag: String) { + if (builder.containsFlagToApi(flag)) { + val updatedApis = builder.getFlagToApiOrThrow(flag).toBuilder().addJavaMethods(api).build() + builder.putFlagToApi(flag, updatedApis) + } else { + val apis = FlaggedApis.newBuilder().addJavaMethods(api).build() + builder.putFlagToApi(flag, apis) + } +} |