Enforce the legacy core/platform API restriction.

This change silently decides whether modules which depend on either
sdkPrivate or sdkCorePlatform get the legacy or the stable version of
the core/platform API, based on whether the module's name is on a
hard-coded list or not.

Test: m java
Test: make a target from the list when its entry is commented out, which correctly fails
Bug: 157640067
Change-Id: I15e5a6c2f07e73718803501d705de0d7ab9bec90
This commit is contained in:
Pete Gillin
2020-07-09 18:03:41 +01:00
parent f9828bf665
commit c0f4373106
7 changed files with 291 additions and 22 deletions

View File

@@ -38,6 +38,7 @@ bootstrap_go_package {
"java_resources.go",
"kotlin.go",
"lint.go",
"legacy_core_platform_api_usage.go",
"platform_compat_config.go",
"plugin.go",
"prebuilt_apis.go",

View File

@@ -30,6 +30,8 @@ var (
LegacyCorePlatformBootclasspathLibraries = []string{"legacy.core.platform.api.stubs", "core-lambda-stubs"}
LegacyCorePlatformSystemModules = "legacy-core-platform-api-stubs-system-modules"
StableCorePlatformBootclasspathLibraries = []string{"stable.core.platform.api.stubs", "core-lambda-stubs"}
StableCorePlatformSystemModules = "stable-core-platform-api-stubs-system-modules"
FrameworkLibraries = []string{"ext", "framework"}
DefaultLambdaStubsLibrary = "core-lambda-stubs"
SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"

View File

@@ -0,0 +1,266 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// 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 java
import (
"android/soong/android"
"android/soong/java/config"
)
var legacyCorePlatformApiModules = []string{
"AAECarSystemUI",
"AAECarSystemUI-tests",
"ahat-test-dump",
"android.car",
"android.test.mock",
"android.test.mock.impl",
"AoapTestDeviceApp",
"AoapTestHostApp",
"api-stubs-docs",
"art_cts_jvmti_test_library",
"art-gtest-jars-MyClassNatives",
"atfwd",
"BackupEncryption",
"BackupFrameworksServicesRoboTests",
"backuplib",
"BandwidthEnforcementTest",
"BlockedNumberProvider",
"BluetoothInstrumentationTests",
"BluetoothMidiLib",
"BluetoothMidiService",
"BTTestApp",
"CallEnhancement",
"CapCtrlInterface",
"CarService",
"car-service-test-lib",
"car-service-test-static-lib",
"CertInstaller",
"com.qti.location.sdk",
"com.qti.media.secureprocessor",
"com.qti.snapdragon.sdk.display",
"ConfURIDialer",
"ConnectivityManagerTest",
"ContactsProvider",
"CorePerfTests",
"core-tests-support",
"cronet_impl_common_java",
"cronet_impl_native_java",
"cronet_impl_platform_java",
"CtsAppExitTestCases",
"CtsContentTestCases",
"CtsIkeTestCases",
"CtsLibcoreWycheproofBCTestCases",
"CtsMediaTestCases",
"CtsNetTestCases",
"CtsNetTestCasesLatestSdk",
"CtsSecurityTestCases",
"CtsSuspendAppsTestCases",
"CtsUsageStatsTestCases",
"datastatusnotification",
"DeadpoolService",
"DeadpoolServiceBtServices",
"DeviceInfo",
"DisplayCutoutEmulationEmu01Overlay",
"DocumentsUIGoogleTests",
"DocumentsUIPerfTests",
"DocumentsUITests",
"DocumentsUIUnitTests",
"DownloadProvider",
"DownloadProviderTests",
"DownloadProviderUi",
"DynamicSystemInstallationService",
"EmergencyInfo-lib",
"ethernet-service",
"EthernetServiceTests",
"ExternalStorageProvider",
"face-V1-0-javalib",
"FloralClocks",
"framework-all",
"framework-jobscheduler",
"framework-minus-apex",
"FrameworkOverlayG6QU3",
"FrameworksCoreTests",
"FrameworksIkeTests",
"FrameworksNetCommonTests",
"FrameworksNetTests",
"FrameworksServicesRoboTests",
"FrameworksServicesTests",
"FrameworksUtilTests",
"FrameworksWifiTests",
"GtsIncrementalInstallTestCases",
"GtsIncrementalInstallTriggerApp",
"GtsInstallerV2TestCases",
"HelloOslo",
"hid",
"hidl_test_java_java",
"hwbinder",
"ims",
"ims-ext-common",
"imssettings",
"izat.lib.glue",
"KeyChain",
"LocalSettingsLib",
"LocalTransport",
"lockagent",
"mediaframeworktest",
"mediatek-ims-base",
"MmsService",
"ModemTestMode",
"MtkCapCtrl",
"MtpService",
"MultiDisplayProvider",
"my.tests.snapdragonsdktest",
"NetworkSetting",
"NetworkStackIntegrationTestsLib",
"NetworkStackNextIntegrationTests",
"NetworkStackNextTests",
"NetworkStackTests",
"NetworkStackTestsLib",
"NfcNci",
"online-gcm-ref-docs",
"online-gts-docs",
"PerformanceMode",
"pixel-power-ext-java",
"pixel-power-ext-unstable-java",
"pixel-power-ext-V1-java",
"platform_library-docs",
"PowerStatsService",
"PrintSpooler",
"pxp-monitor",
"QColor",
"qcom.fmradio",
"qcrilhook",
"qcrilhook-static",
"qcrilmsgtunnel",
"QDCMMobileApp",
"Qmmi",
"QPerformance",
"QtiTelephonyService",
"QtiTelephonyServicelibrary",
"remoteSimLockAuthentication",
"remotesimlockmanagerlibrary",
"RollbackTest",
"sam",
"saminterfacelibrary",
"sammanagerlibrary",
"service-blobstore",
"service-jobscheduler",
"services",
"services.accessibility",
"services.backup",
"services.core.unboosted",
"services.devicepolicy",
"services.print",
"services.usage",
"services.usb",
"Settings-core",
"SettingsGoogleOverlayCoral",
"SettingsGoogleOverlayFlame",
"SettingsLib",
"SettingsOverlayG013A",
"SettingsOverlayG013B",
"SettingsOverlayG013C",
"SettingsOverlayG013D",
"SettingsOverlayG020A",
"SettingsOverlayG020B",
"SettingsOverlayG020C",
"SettingsOverlayG020D",
"SettingsOverlayG020E",
"SettingsOverlayG020E_VN",
"SettingsOverlayG020F",
"SettingsOverlayG020F_VN",
"SettingsOverlayG020G",
"SettingsOverlayG020G_VN",
"SettingsOverlayG020H",
"SettingsOverlayG020H_VN",
"SettingsOverlayG020I",
"SettingsOverlayG020I_VN",
"SettingsOverlayG020J",
"SettingsOverlayG020M",
"SettingsOverlayG020N",
"SettingsOverlayG020P",
"SettingsOverlayG020Q",
"SettingsOverlayG025H",
"SettingsOverlayG025J",
"SettingsOverlayG025M",
"SettingsOverlayG025N",
"SettingsOverlayG5NZ6",
"SettingsProvider",
"SettingsProviderTest",
"Shell",
"ShellTests",
"SimContact",
"SimContacts",
"SimSettings",
"sl4a.Common",
"StatementService",
"SystemUI-core",
"SystemUISharedLib",
"SystemUI-tests",
"tcmiface",
"Telecom",
"TelecomUnitTests",
"telephony-common",
"telephony-ext",
"TelephonyProviderTests",
"TeleService",
"testables",
"TetheringTests",
"TetheringTestsLib",
"time_zone_distro_installer",
"time_zone_distro_installer-tests",
"time_zone_distro-tests",
"time_zone_updater",
"TMobilePlanProvider",
"TvProvider",
"uiautomator-stubs-docs",
"uimgbamanagerlibrary",
"UsbHostExternalManagementTestApp",
"UserDictionaryProvider",
"UxPerformance",
"WallpaperBackup",
"WallpaperBackupAgentTests",
"WfdCommon",
"xdivert",
}
var legacyCorePlatformApiLookup = make(map[string]struct{})
func init() {
for _, module := range legacyCorePlatformApiModules {
legacyCorePlatformApiLookup[module] = struct{}{}
}
}
func useLegacyCorePlatformApi(ctx android.EarlyModuleContext) bool {
_, found := legacyCorePlatformApiLookup[ctx.ModuleName()]
return found
}
func corePlatformSystemModules(ctx android.EarlyModuleContext) string {
if useLegacyCorePlatformApi(ctx) {
return config.LegacyCorePlatformSystemModules
} else {
return config.StableCorePlatformSystemModules
}
}
func corePlatformBootclasspathLibraries(ctx android.EarlyModuleContext) []string {
if useLegacyCorePlatformApi(ctx) {
return config.LegacyCorePlatformBootclasspathLibraries
} else {
return config.StableCorePlatformBootclasspathLibraries
}
}

View File

@@ -413,8 +413,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep
case sdkPrivate:
return sdkDep{
useModule: true,
systemModules: config.LegacyCorePlatformSystemModules,
bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
systemModules: corePlatformSystemModules(ctx),
bootclasspath: corePlatformBootclasspathLibraries(ctx),
classpath: config.FrameworkLibraries,
frameworkResModule: "framework-res",
}
@@ -438,8 +438,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep
case sdkCorePlatform:
return sdkDep{
useModule: true,
systemModules: config.LegacyCorePlatformSystemModules,
bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
systemModules: corePlatformSystemModules(ctx),
bootclasspath: corePlatformBootclasspathLibraries(ctx),
noFrameworksLibs: true,
}
case sdkPublic:

View File

@@ -49,8 +49,8 @@ func TestClasspath(t *testing.T) {
}{
{
name: "default",
bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
system: config.LegacyCorePlatformSystemModules,
bootclasspath: config.StableCorePlatformBootclasspathLibraries,
system: config.StableCorePlatformSystemModules,
java8classpath: config.FrameworkLibraries,
java9classpath: config.FrameworkLibraries,
aidl: "-Iframework/aidl",
@@ -58,16 +58,16 @@ func TestClasspath(t *testing.T) {
{
name: `sdk_version:"core_platform"`,
properties: `sdk_version:"core_platform"`,
bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
system: config.LegacyCorePlatformSystemModules,
bootclasspath: config.StableCorePlatformBootclasspathLibraries,
system: config.StableCorePlatformSystemModules,
java8classpath: []string{},
aidl: "",
},
{
name: "blank sdk version",
properties: `sdk_version: "",`,
bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
system: config.LegacyCorePlatformSystemModules,
bootclasspath: config.StableCorePlatformBootclasspathLibraries,
system: config.StableCorePlatformSystemModules,
java8classpath: config.FrameworkLibraries,
java9classpath: config.FrameworkLibraries,
aidl: "-Iframework/aidl",
@@ -155,9 +155,9 @@ func TestClasspath(t *testing.T) {
{
name: "nostdlib system_modules",
properties: `sdk_version: "none", system_modules: "legacy-core-platform-api-stubs-system-modules"`,
system: "legacy-core-platform-api-stubs-system-modules",
bootclasspath: []string{"legacy-core-platform-api-stubs-system-modules-lib"},
properties: `sdk_version: "none", system_modules: "stable-core-platform-api-stubs-system-modules"`,
system: "stable-core-platform-api-stubs-system-modules",
bootclasspath: []string{"stable-core-platform-api-stubs-system-modules-lib"},
java8classpath: []string{},
},
{

View File

@@ -135,7 +135,7 @@ func GatherRequiredDepsForTest() string {
name: "%s",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
}
`, extra)
}
@@ -145,7 +145,7 @@ func GatherRequiredDepsForTest() string {
name: "framework",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
aidl: {
export_include_dirs: ["framework/aidl"],
},
@@ -160,7 +160,7 @@ func GatherRequiredDepsForTest() string {
name: "android.hidl.base-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -168,7 +168,7 @@ func GatherRequiredDepsForTest() string {
name: "android.hidl.manager-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -176,7 +176,7 @@ func GatherRequiredDepsForTest() string {
name: "org.apache.http.legacy",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -184,7 +184,7 @@ func GatherRequiredDepsForTest() string {
name: "android.test.base",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -192,7 +192,7 @@ func GatherRequiredDepsForTest() string {
name: "android.test.mock",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "legacy-core-platform-api-stubs-system-modules",
system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
`

View File

@@ -51,10 +51,10 @@ java_system_modules_import {
name: "core-current-stubs-system-modules",
}
java_system_modules_import {
name: "legacy-core-platform-api-stubs-system-modules",
name: "stable-core-platform-api-stubs-system-modules",
}
java_import {
name: "legacy.core.platform.api.stubs",
name: "stable.core.platform.api.stubs",
}
java_import {
name: "android_stubs_current",