diff --git a/android/apex.go b/android/apex.go index 8482dc2ce..0b901ae87 100644 --- a/android/apex.go +++ b/android/apex.go @@ -144,9 +144,9 @@ const ( func CheckAvailableForApex(what string, apex_available []string) bool { if len(apex_available) == 0 { - // apex_available defaults to ["//apex_available:platform", "//apex_available:anyapex"], - // which means 'available to everybody'. - return true + // apex_available defaults to ["//apex_available:platform"], + // which means 'available to the platform but no apexes'. + return what == AvailableToPlatform } return InList(what, apex_available) || (what != AvailableToPlatform && InList(availableToAnyApex, apex_available)) diff --git a/apex/apex.go b/apex/apex.go index 7d6b7f00f..f3eebd40e 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -57,8 +57,266 @@ var ( certificateTag = dependencyTag{name: "certificate"} usesTag = dependencyTag{name: "uses"} androidAppTag = dependencyTag{name: "androidApp"} + apexAvailWl = makeApexAvailableWhitelist() ) +// This is a map from apex to modules, which overrides the +// apex_available setting for that particular module to make +// it available for the apex regardless of its setting. +// TODO(b/147364041): remove this +func makeApexAvailableWhitelist() map[string][]string { + // The "Module separator"s below are employed to minimize merge conflicts. + m := make(map[string][]string) + // + // Module separator + // + m["com.android.adbd"] = []string{"adbd", "libcrypto"} + // + // Module separator + // + m["com.android.art"] = []string{ + "libadbconnection_server", + "libartd-disassembler", + "libbacktrace", + "libbase", + "libc++", + "libcrypto", + "libdexfile_support", + "libexpat", + "libicuuc", + "liblzma", + "libmeminfo", + "libprocinfo", + "libunwindstack", + "libvixl", + "libvixld", + "libz", + "libziparchive", + "prebuilt_libclang_rt", + } + // + // Module separator + // + m["com.android.bluetooth.updatable"] = []string{ + "android.hardware.audio.common@5.0", + "android.hardware.bluetooth@1.0", + "android.hardware.bluetooth@1.1", + "android.hardware.bluetooth.a2dp@1.0", + "android.hardware.bluetooth.audio@2.0", + "android.hidl.safe_union@1.0", + "libbase", + "libbinderthreadstate", + "libbluetooth", + "libbluetooth_jni", + "libc++", + "libchrome", + "libcrypto", + "libcutils", + "libevent", + "libfmq", + "libhidlbase", + "libprocessgroup", + "libprotobuf-cpp-lite", + "libstatslog", + "libtinyxml2", + "libutils", + "libz", + } + // + // Module separator + // + m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"} + // + // Module separator + // + m["com.android.conscrypt"] = []string{"boringssl_self_test", "libc++", "libcrypto", "libssl"} + // + // Module separator + // + m["com.android.cronet"] = []string{"org.chromium.net.cronet", "prebuilt_libcronet.80.0.3986.0"} + // + // Module separator + // + m["com.android.incremental"] = []string{"libc++", "libdataloader", "libincfs"} + // + // Module separator + // + m["com.android.media"] = []string{ + "android.hardware.cas@1.0", + "android.hardware.cas.native@1.0", + "android.hidl.allocator@1.0", + "android.hidl.memory@1.0", + "android.hidl.memory.token@1.0", + "android.hidl.token@1.0", + "android.hidl.token@1.0-utils", + "libaacextractor", + "libamrextractor", + "libaudioutils", + "libbase", + "libbinderthreadstate", + "libc++", + "libcrypto", + "libcutils", + "libflacextractor", + "libhidlbase", + "libhidlmemory", + "libmidiextractor", + "libmkvextractor", + "libmp3extractor", + "libmp4extractor", + "libmpeg2extractor", + "liboggextractor", + "libprocessgroup", + "libspeexresampler", + "libstagefright_flacdec", + "libutils", + "libwavextractor", + "updatable-media", + } + // + // Module separator + // + m["com.android.media.swcodec"] = []string{ + "android.frameworks.bufferhub@1.0", + "android.hardware.common-ndk_platform", + "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.allocator@3.0", + "android.hardware.graphics.allocator@4.0", + "android.hardware.graphics.bufferqueue@1.0", + "android.hardware.graphics.bufferqueue@2.0", + "android.hardware.graphics.common@1.0", + "android.hardware.graphics.common@1.1", + "android.hardware.graphics.common@1.2", + "android.hardware.graphics.common-ndk_platform", + "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.1", + "android.hardware.graphics.mapper@3.0", + "android.hardware.graphics.mapper@4.0", + "android.hardware.media@1.0", + "android.hardware.media.bufferpool@2.0", + "android.hardware.media.c2@1.0", + "android.hardware.media.c2@1.1", + "android.hardware.media.omx@1.0", + "android.hidl.memory@1.0", + "android.hidl.memory.token@1.0", + "android.hidl.safe_union@1.0", + "android.hidl.token@1.0", + "android.hidl.token@1.0-utils", + "libaudioutils", + "libavservices_minijail", + "libbase", + "libbinderthreadstate", + "libc++", + "libcap", + "libcodec2", + "libcodec2_hidl@1.0", + "libcodec2_hidl@1.1", + "libcodec2_soft_aacdec", + "libcodec2_soft_aacenc", + "libcodec2_soft_amrnbdec", + "libcodec2_soft_amrnbenc", + "libcodec2_soft_amrwbdec", + "libcodec2_soft_amrwbenc", + "libcodec2_soft_av1dec_gav1", + "libcodec2_soft_avcdec", + "libcodec2_soft_avcenc", + "libcodec2_soft_common", + "libcodec2_soft_flacdec", + "libcodec2_soft_flacenc", + "libcodec2_soft_g711alawdec", + "libcodec2_soft_g711mlawdec", + "libcodec2_soft_gsmdec", + "libcodec2_soft_h263dec", + "libcodec2_soft_h263enc", + "libcodec2_soft_hevcdec", + "libcodec2_soft_hevcenc", + "libcodec2_soft_mp3dec", + "libcodec2_soft_mpeg2dec", + "libcodec2_soft_mpeg4dec", + "libcodec2_soft_mpeg4enc", + "libcodec2_soft_opusdec", + "libcodec2_soft_opusenc", + "libcodec2_soft_rawdec", + "libcodec2_soft_vorbisdec", + "libcodec2_soft_vp8dec", + "libcodec2_soft_vp8enc", + "libcodec2_soft_vp9dec", + "libcodec2_soft_vp9enc", + "libcodec2_vndk", + "libc_scudo", + "libcutils", + "libfmq", + "libgralloctypes", + "libhardware", + "libhidlbase", + "libhidlmemory", + "libion", + "libmedia_codecserviceregistrant", + "libminijail", + "libopus", + "libprocessgroup", + "libscudo_wrapper", + "libsfplugin_ccodec_utils", + "libspeexresampler", + "libstagefright_amrnb_common", + "libstagefright_bufferpool@2.0.1", + "libstagefright_bufferqueue_helper", + "libstagefright_enc_common", + "libstagefright_flacdec", + "libstagefright_foundation", + "libsync", + "libui", + "libutils", + "libvorbisidec", + "libvpx", + "mediaswcodec", + "prebuilt_libclang_rt", + } + // + // Module separator + // + m["com.android.mediaprovider"] = []string{"libfuse", "MediaProvider", "MediaProviderGoogle"} + // + // Module separator + // + m["com.android.permission"] = []string{"GooglePermissionController", "PermissionController"} + // + // Module separator + // + m["com.android.runtime"] = []string{ + "libbase", + "libc++", + "libdexfile_support", + "liblzma", + "libunwindstack", + "prebuilt_libclang_rt", + } + // + // Module separator + // + m["com.android.resolv"] = []string{"libcrypto", "libnetd_resolv", "libssl"} + // + // Module separator + // + m["com.android.tethering"] = []string{"libbase", "libc++", "libnativehelper_compat_libc++"} + // + // Module separator + // + m["com.android.wifi"] = []string{ + "libbase", + "libc++", + "libcutils", + "libprocessgroup", + "libutils", + "libwifi-jni", + "wifi-service-resources", + } + // + // Module separator + // + return m +} + func init() { android.RegisterModuleType("apex", BundleFactory) android.RegisterModuleType("apex_test", testApexBundleFactory) @@ -1231,7 +1489,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { if !ctx.Host() && !a.testApex { for _, fi := range filesInfo { if am, ok := fi.module.(android.ApexModule); ok { - if !am.AvailableFor(ctx.ModuleName()) { + // vndk {enabled:true} implies visibility to the vndk apex + if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex { + continue + } + + if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) { ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name()) // don't stop so that we can report other violations in the same run } @@ -1280,6 +1543,25 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.buildApexDependencyInfo(ctx) } +func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool { + key := apex + key = strings.Replace(key, "test_", "", 1) + key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1) + key = strings.Replace(key, "com.android.art.release", "com.android.art", 1) + + moduleName := module.Name() + if strings.Contains(moduleName, "prebuilt_libclang_rt") { + // This module has variants that depend on the product being built. + moduleName = "prebuilt_libclang_rt" + } + + if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) { + return true + } + + return false +} + func newApexBundle() *apexBundle { module := &apexBundle{} module.AddProperties(&module.properties) diff --git a/apex/apex_test.go b/apex/apex_test.go index b37674ff1..80decd087 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -403,6 +403,11 @@ func TestBasicApex(t *testing.T) { shared_libs: ["mylib2"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } cc_binary { @@ -422,6 +427,7 @@ func TestBasicApex(t *testing.T) { system_shared_libs: [], static_executable: true, stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -430,6 +436,11 @@ func TestBasicApex(t *testing.T) { system_shared_libs: [], stl: "none", notice: "custom_notice", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } java_library { @@ -440,6 +451,11 @@ func TestBasicApex(t *testing.T) { compile_dex: true, static_libs: ["myotherjar"], libs: ["mysharedjar"], + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } java_library { @@ -560,6 +576,7 @@ func TestDefaults(t *testing.T) { name: "mylib", system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } java_library { @@ -568,6 +585,7 @@ func TestDefaults(t *testing.T) { sdk_version: "none", system_modules: "none", compile_dex: true, + apex_available: [ "myapex" ], } android_app { @@ -575,6 +593,7 @@ func TestDefaults(t *testing.T) { srcs: ["foo/bar/MyClass.java"], sdk_version: "none", system_modules: "none", + apex_available: [ "myapex" ], } `) ensureExactContents(t, ctx, "myapex", []string{ @@ -627,6 +646,7 @@ func TestBasicZipApex(t *testing.T) { shared_libs: ["mylib2"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -634,6 +654,7 @@ func TestBasicZipApex(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `) @@ -674,6 +695,7 @@ func TestApexWithStubs(t *testing.T) { shared_libs: ["mylib2", "mylib3"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -696,6 +718,7 @@ func TestApexWithStubs(t *testing.T) { stubs: { versions: ["10", "11", "12"], }, + apex_available: [ "myapex" ], } cc_library { @@ -703,6 +726,7 @@ func TestApexWithStubs(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `) @@ -764,6 +788,7 @@ func TestApexWithExplicitStubsDependency(t *testing.T) { shared_libs: ["libfoo#10"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex2" ], } cc_library { @@ -845,6 +870,7 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { runtime_libs: ["libfoo", "libbar"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -862,6 +888,7 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `) @@ -906,6 +933,7 @@ func TestApexDependencyToLLNDK(t *testing.T) { shared_libs: ["libbar"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -956,6 +984,7 @@ func TestApexWithSystemLibsStubs(t *testing.T) { srcs: ["mylib.cpp"], shared_libs: ["libdl#27"], stl: "none", + apex_available: [ "myapex" ], } cc_library_shared { @@ -963,6 +992,7 @@ func TestApexWithSystemLibsStubs(t *testing.T) { srcs: ["mylib.cpp"], shared_libs: ["libdl#27"], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -985,6 +1015,10 @@ func TestApexWithSystemLibsStubs(t *testing.T) { stubs: { versions: ["27", "28", "29"], }, + apex_available: [ + "//apex_available:platform", + "myapex" + ], } cc_library { @@ -996,6 +1030,10 @@ func TestApexWithSystemLibsStubs(t *testing.T) { stubs: { versions: ["27", "28", "29"], }, + apex_available: [ + "//apex_available:platform", + "myapex" + ], } cc_library { @@ -1087,6 +1125,7 @@ func TestFilesInSubDir(t *testing.T) { relative_install_path: "foo/bar", system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_binary { @@ -1096,6 +1135,7 @@ func TestFilesInSubDir(t *testing.T) { system_shared_libs: [], static_executable: true, stl: "none", + apex_available: [ "myapex" ], } `) @@ -1140,6 +1180,7 @@ func TestUseVendor(t *testing.T) { system_shared_libs: [], vendor_available: true, stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -1148,6 +1189,7 @@ func TestUseVendor(t *testing.T) { system_shared_libs: [], vendor_available: true, stl: "none", + apex_available: [ "myapex" ], } `, func(fs map[string][]byte, config android.Config) { setUseVendorWhitelistForTest(config, []string{"myapex"}) @@ -1248,6 +1290,10 @@ func TestStaticLinking(t *testing.T) { stubs: { versions: ["1", "2", "3"], }, + apex_available: [ + "//apex_available:platform", + "myapex", + ], } cc_binary { @@ -1281,6 +1327,7 @@ func TestKeys(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex_keytest" ], } apex_key { @@ -1474,6 +1521,12 @@ func TestMacro(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + "otherapex", + ], } `) @@ -1527,6 +1580,7 @@ func TestHeaderLibsDependency(t *testing.T) { stubs: { versions: ["1", "2", "3"], }, + apex_available: [ "myapex" ], } cc_library { @@ -1629,6 +1683,7 @@ func TestVndkApexCurrent(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -1641,6 +1696,7 @@ func TestVndkApexCurrent(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `+vndkLibrariesTxtFiles("current")) @@ -1678,6 +1734,7 @@ func TestVndkApexWithPrebuilt(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_prebuilt_library_shared { @@ -1695,6 +1752,7 @@ func TestVndkApexWithPrebuilt(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ @@ -1765,6 +1823,7 @@ func TestVndkApexVersion(t *testing.T) { srcs: ["libvndk27_arm64.so"], }, }, + apex_available: [ "myapex_v27" ], } vndk_prebuilt_shared { @@ -1901,6 +1960,7 @@ func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } `+vndkLibrariesTxtFiles("current"), withTargets(map[android.OsType][]android.Target{ @@ -1993,6 +2053,7 @@ func TestVndkApexWithBinder32(t *testing.T) { srcs: ["libvndk27binder32.so"], } }, + apex_available: [ "myapex_v27" ], } `+vndkLibrariesTxtFiles("27"), withFiles(map[string][]byte{ @@ -2058,6 +2119,7 @@ func TestDependenciesInApexManifest(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex_nodep" ], } cc_library { @@ -2066,6 +2128,11 @@ func TestDependenciesInApexManifest(t *testing.T) { shared_libs: ["libfoo"], system_shared_libs: [], stl: "none", + apex_available: [ + "myapex_dep", + "myapex_provider", + "myapex_selfcontained", + ], } cc_library { @@ -2076,6 +2143,10 @@ func TestDependenciesInApexManifest(t *testing.T) { }, system_shared_libs: [], stl: "none", + apex_available: [ + "myapex_provider", + "myapex_selfcontained", + ], } `) @@ -2148,6 +2219,10 @@ func TestNonTestApex(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + apex_available: [ + "//apex_available:platform", + "myapex", + ], } `) @@ -2199,6 +2274,11 @@ func TestTestApex(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } `) @@ -2267,6 +2347,11 @@ func TestApexWithTarget(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } cc_library { @@ -2275,6 +2360,11 @@ func TestApexWithTarget(t *testing.T) { system_shared_libs: [], stl: "none", compile_multilib: "first", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } cc_library { @@ -2701,6 +2791,7 @@ func TestApexUsesOtherApex(t *testing.T) { shared_libs: ["libcommon"], system_shared_libs: [], stl: "none", + apex_available: [ "myapex" ], } cc_library { @@ -2708,6 +2799,12 @@ func TestApexUsesOtherApex(t *testing.T) { srcs: ["mylib_common.cpp"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "commonapex", + "myapex", + ], } `) @@ -2859,6 +2956,7 @@ func TestApexWithApps(t *testing.T) { sdk_version: "none", system_modules: "none", jni_libs: ["libjni"], + apex_available: [ "myapex" ], } android_app { @@ -2867,6 +2965,7 @@ func TestApexWithApps(t *testing.T) { sdk_version: "none", system_modules: "none", privileged: true, + apex_available: [ "myapex" ], } cc_library_shared { @@ -2960,6 +3059,7 @@ func TestApexWithTestHelperApp(t *testing.T) { android_test_helper_app { name: "TesterHelpAppFoo", srcs: ["foo/bar/MyClass.java"], + apex_available: [ "myapex" ], } `) @@ -3215,6 +3315,7 @@ func TestOverrideApex(t *testing.T) { package_name: "foo", sdk_version: "none", system_modules: "none", + apex_available: [ "myapex" ], } override_android_app { @@ -3298,6 +3399,7 @@ func TestJavaSDKLibrary(t *testing.T) { name: "foo", srcs: ["a.java"], api_packages: ["foo"], + apex_available: [ "myapex" ], } `, withFiles(map[string][]byte{ "api/current.txt": nil, @@ -3363,6 +3465,7 @@ func TestCarryRequiredModuleNames(t *testing.T) { required: ["a", "b"], host_required: ["c", "d"], target_required: ["e", "f"], + apex_available: [ "myapex" ], } `) diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 255ac08a5..9a75610f6 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -101,6 +101,11 @@ func TestBasicSdkWithCc(t *testing.T) { srcs: ["libfoo.so"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex", + ], } cc_prebuilt_library_shared { @@ -109,6 +114,11 @@ func TestBasicSdkWithCc(t *testing.T) { srcs: ["libfoo.so"], system_shared_libs: [], stl: "none", + // TODO: remove //apex_available:platform + apex_available: [ + "//apex_available:platform", + "myapex2", + ], } cc_library_shared { @@ -117,6 +127,10 @@ func TestBasicSdkWithCc(t *testing.T) { shared_libs: ["sdkmember"], system_shared_libs: [], stl: "none", + apex_available: [ + "myapex", + "myapex2", + ], } apex { diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 218a16a89..692c2051e 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -73,6 +73,10 @@ func TestBasicSdkWithJavaLibrary(t *testing.T) { sdk_version: "none", compile_dex: true, host_supported: true, + apex_available: [ + "myapex", + "myapex2", + ], } apex {