From 0493165fde8e23edd3dd3e91f5eb6fc0d62892f6 Mon Sep 17 00:00:00 2001 From: Pedro Loureiro Date: Wed, 22 Dec 2021 19:53:01 +0000 Subject: Rename updatable-library to apex-library Mostly for consistency with the names used in related changes. Test: m nothing Bug: 191978330 Change-Id: I34637986ead1c671bcc649891aceb3fe0f44b52a --- java/sdk_library.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'java/sdk_library.go') diff --git a/java/sdk_library.go b/java/sdk_library.go index b8ab69abb..57ab2686f 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2573,11 +2573,11 @@ func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) stri implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before) minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk) maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk) - // is understood in all android versions whereas is only understood from API T (and ignored before that). - // similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the updatable-library to make sure this library is not loaded before T + // is understood in all android versions whereas is only understood from API T (and ignored before that). + // similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T var libraryTag string if module.properties.Min_device_sdk != nil { - libraryTag = ` Date: Thu, 28 Apr 2022 14:13:30 +0000 Subject: Allow framework-media to build the framework-media.impl (cherry picked from commit 77590a82638fdd3d1d9e12cd57270e1a9cb2eaa7) The framework-media java_sdk_library is currently api_only for legacy reasons. This change allows it to also build the framework-media.impl library by making the following changes: * Adds impl_only_static_libs to allow the implementation to statically include other libraries, something no other java_sdk_library has needed to do. * Passes the apex_availability property through to the impl library so it can be statically included in the updatable-media which is what is included in the apex, again for legacy reasons. Bug: 190807367 Bug: 229932396 Test: m com.android.media media-module-sdk # Compare before and after this change (and corresponding change # to updatable-media/framework-media. Merged-In: I9e1837edcca6f5fa84fc611274cf8fbba8a896b8 Change-Id: I9e1837edcca6f5fa84fc611274cf8fbba8a896b8 --- java/sdk_library.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'java/sdk_library.go') diff --git a/java/sdk_library.go b/java/sdk_library.go index c37ed1a27..fb032559e 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -377,6 +377,9 @@ type sdkLibraryProperties struct { // List of Java libraries that will be in the classpath when building the implementation lib Impl_only_libs []string `android:"arch_variant"` + // List of Java libraries that will included in the implementation lib. + Impl_only_static_libs []string `android:"arch_variant"` + // List of Java libraries that will be in the classpath when building stubs Stub_only_libs []string `android:"arch_variant"` @@ -1346,10 +1349,12 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) props := struct { - Name *string - Visibility []string - Instrument bool - Libs []string + Name *string + Visibility []string + Instrument bool + Libs []string + Static_libs []string + Apex_available []string }{ Name: proptools.StringPtr(module.implLibraryModuleName()), Visibility: visibility, @@ -1358,6 +1363,12 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the // addition of &module.properties below. Libs: module.sdkLibraryProperties.Impl_only_libs, + // Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the + // addition of &module.properties below. + Static_libs: module.sdkLibraryProperties.Impl_only_static_libs, + // Pass the apex_available settings down so that the impl library can be statically + // embedded within a library that is added to an APEX. Needed for updatable-media. + Apex_available: module.ApexAvailable(), } properties := []interface{}{ @@ -1814,8 +1825,9 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } - // Add the impl_only_libs *after* we're done using the Libs prop in submodules. + // Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) + module.properties.Static_libs = append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...) } func (module *SdkLibrary) InitSdkLibraryProperties() { -- cgit v1.2.3-59-g8ed1b From 3cf140fe98baf01cfc35a52a551d5e6d41159ed7 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 29 Apr 2022 14:21:25 +0100 Subject: java_sdk_library_import: Delegate OutputFiles to impl library if needed Bug: 230846030 Test: m nothing # Cherry pick into build with prebuilts enabled to verify. Merged-In: I5ac9b1cdd2fc61efbc988e84556202ff6cd57146 Change-Id: I5ac9b1cdd2fc61efbc988e84556202ff6cd57146 (cherry picked from commit 1e940d5b449148105e33d75cbef4bbde307bf1f9) --- java/sdk_library.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'java/sdk_library.go') diff --git a/java/sdk_library.go b/java/sdk_library.go index fb032559e..2c67767bf 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2224,7 +2224,15 @@ func (module *SdkLibraryImport) UniqueApexVariations() bool { } func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { - return module.commonOutputFiles(tag) + paths, err := module.commonOutputFiles(tag) + if paths != nil || err != nil { + return paths, err + } + if module.implLibraryModule != nil { + return module.implLibraryModule.OutputFiles(tag) + } else { + return nil, nil + } } func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { -- cgit v1.2.3-59-g8ed1b From a80cc174a2b56b53c8fed1cf6c868f760404b3c1 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 28 Apr 2022 17:45:11 +0100 Subject: hiddenapi: Prevent libraries for Q/R from include S+ flags. The Q and R runtimes can handle Q/R flags but not S flags. So, this change verifies that any library that can run on Q/R (min_sdk_version <= R) by adding --max-hiddenapi-level=max-target-r to the "hiddenapi encode" command. That will cause a failure if any S+ flags are found in the flags to encode. Bug: 172453495 Test: m droid && launch_cvd Cherry pick changes in https://r.android.com/q/topic:max-target-s Add @UnsupportedAppUsage maxTargetSdk=S in classes in framework-permission (for r/q) and framework-permission-s (nominally for S+). I had to incresed the min_sdk_version in the latter to 31 (S) as it was still set at 30 (R). Merged-In: Ie0f68482603adc7b4e3d7a5c81bf203d81a84a9e Change-Id: Ie0f68482603adc7b4e3d7a5c81bf203d81a84a9e (cherry picked from commit 09817d66dea3639528b35a5b61ddce78766d198c) --- java/hiddenapi.go | 15 +++++++++++++-- java/hiddenapi_modular.go | 6 +++++- java/sdk_library.go | 7 +++++++ 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'java/sdk_library.go') diff --git a/java/hiddenapi.go b/java/hiddenapi.go index 3af5f1c7b..cf9c7ad7a 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -65,6 +65,8 @@ func (h *hiddenAPI) uncompressDex() *bool { type hiddenAPIModule interface { android.Module hiddenAPIIntf + + MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec } type hiddenAPIIntf interface { @@ -148,7 +150,7 @@ func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android // Create a copy of the dex jar which has been encoded with hiddenapi flags. flagsCSV := hiddenAPISingletonPaths(ctx).flags outputDir := android.PathForModuleOut(ctx, "hiddenapi").OutputPath - encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, outputDir) + encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, android.SdkSpecNone, outputDir) // Use the encoded dex jar from here onwards. return encodedDex @@ -246,7 +248,7 @@ var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", bluepr // The encode dex rule requires unzipping, encoding and rezipping the classes.dex files along with // all the resources from the input jar. It also ensures that if it was uncompressed in the input // it stays uncompressed in the output. -func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, outputDir android.OutputPath) android.OutputPath { +func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, minSdkVersion android.SdkSpec, outputDir android.OutputPath) android.OutputPath { // The output file has the same name as the input file and is in the output directory. output := outputDir.Join(ctx, dexInput.Base()) @@ -274,6 +276,15 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Pa hiddenapiFlags = "--no-force-assign-all" } + // If the library is targeted for Q and/or R then make sure that they do not + // have any S+ flags encoded as that will break the runtime. + minApiLevel := minSdkVersion.ApiLevel + if !minApiLevel.IsNone() { + if minApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(ctx, "R")) { + hiddenapiFlags = hiddenapiFlags + " --max-hiddenapi-level=max-target-r" + } + } + ctx.Build(pctx, android.BuildParams{ Rule: hiddenAPIEncodeDexRule, Description: "hiddenapi encode dex", diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 534a8145f..c90b2ff97 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -1104,7 +1104,7 @@ func hiddenAPIRulesForBootclasspathFragment(ctx android.ModuleContext, contents for _, name := range android.SortedStringKeys(bootDexInfoByModule) { bootDexInfo := bootDexInfoByModule[name] unencodedDex := bootDexInfo.path - encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, outputDir) + encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) encodedBootDexJarsByModule[name] = encodedDex } @@ -1188,6 +1188,9 @@ type bootDexInfo struct { // Indicates whether the dex jar needs uncompressing before encoding. uncompressDex bool + + // The minimum sdk version that the dex jar will be used on. + minSdkVersion android.SdkSpec } // bootDexInfoByModule is a map from module name (as returned by module.Name()) to the boot dex @@ -1213,6 +1216,7 @@ func extractBootDexInfoFromModules(ctx android.ModuleContext, contents []android bootDexJarsByModule[module.Name()] = bootDexInfo{ path: bootDexJar, uncompressDex: *hiddenAPIModule.uncompressDex(), + minSdkVersion: hiddenAPIModule.MinSdkVersion(ctx), } } diff --git a/java/sdk_library.go b/java/sdk_library.go index fb032559e..031848e36 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2223,6 +2223,13 @@ func (module *SdkLibraryImport) UniqueApexVariations() bool { return module.uniqueApexVariations() } +// MinSdkVersion - Implements hiddenAPIModule +func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { + return android.SdkSpecNone +} + +var _ hiddenAPIModule = (*SdkLibraryImport)(nil) + func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { return module.commonOutputFiles(tag) } -- cgit v1.2.3-59-g8ed1b From 489912283e29c4ee07754b185e984eddd90fb067 Mon Sep 17 00:00:00 2001 From: Pedro Loureiro Date: Fri, 17 Jun 2022 20:01:21 +0000 Subject: Translate SDK codenames to SDK versions for finalized releases This applies to updatability attributes of shared libraries. Bug: 235318264 Test: atest UpdatableSharedLibsTest Change-Id: Id2c2b769a99ca1debb5d8525e46d37698ef2fc6c --- java/sdk_library.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'java/sdk_library.go') diff --git a/java/sdk_library.go b/java/sdk_library.go index cd8e8755e..47ffc6afc 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2584,7 +2584,10 @@ func formattedOptionalSdkLevelAttribute(ctx android.ModuleContext, attrName stri `"current" is not an allowed value for this attribute`) return "" } - return formattedOptionalAttribute(attrName, value) + // "safeValue" is safe because it translates finalized codenames to a string + // with their SDK int. + safeValue := apiLevel.String() + return formattedOptionalAttribute(attrName, &safeValue) } // formats an attribute for the xml permissions file if the value is not null -- cgit v1.2.3-59-g8ed1b