From 38c64f62cf1fb6afb02c2cdfe99cc1956977bf08 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Mon, 12 Feb 2024 15:00:15 +0000 Subject: [PATCH] Restrict verify_overlaps to pre S modules The runtime in S and above does not have the same constraints that require the hiddenapi flags to be generated in a monolithic manner. This CL restricts the verify_overlaps to pre S modules. This will filter out hiddenapi signature discrepancies that do not require any action. Test: verify_overlaps diff with this change https://diff.googleplex.com/#key=xxB0ky93hZRn Test: presubmits Bug: 313672880 Change-Id: Ie626a6779fc924563bec90b6c1ab0c7e8b4b23c2 --- android/api_levels.go | 2 ++ apex/platform_bootclasspath_test.go | 12 +++++++----- java/hiddenapi_monolithic.go | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/android/api_levels.go b/android/api_levels.go index c019f99ab..6fa4a0e41 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -288,6 +288,8 @@ var FirstPackedRelocationsVersion = uncheckedFinalApiLevel(23) // a core-for-system-modules.jar for the module-lib API scope. var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31) +var ApiLevelR = uncheckedFinalApiLevel(30) + // ReplaceFinalizedCodenames returns the API level number associated with that API level // if the `raw` input is the codename of an API level has been finalized. // If the input is *not* a finalized codename, the input is returned unmodified. diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 2bd3159be..2be9c10e1 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -86,6 +86,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { "bar-fragment", ], updatable: false, + min_sdk_version: "30", // R } apex_key { @@ -138,6 +139,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { sdk_version: "none", compile_dex: true, permitted_packages: ["bar"], + min_sdk_version: "30", // R } java_sdk_library { @@ -162,12 +164,12 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category]) } - android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths) - android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/metadata.csv"}, info.MetadataPaths) - android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/index.csv"}, info.IndexPaths) + android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths) + android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/metadata.csv"}, info.MetadataPaths) + android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/index.csv"}, info.IndexPaths) - android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) - android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) + android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) + android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) } // TestPlatformBootclasspath_LegacyPrebuiltFragment verifies that the diff --git a/java/hiddenapi_monolithic.go b/java/hiddenapi_monolithic.go index a61018d84..1e30c5f82 100644 --- a/java/hiddenapi_monolithic.go +++ b/java/hiddenapi_monolithic.go @@ -68,7 +68,7 @@ func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory F case *ClasspathFragmentElement: fragment := e.Module() if info, ok := android.OtherModuleProvider(ctx, fragment, HiddenAPIInfoProvider); ok { - monolithicInfo.append(&info) + monolithicInfo.append(ctx, fragment, &info) } else { ctx.ModuleErrorf("%s does not provide hidden API information", fragment) } @@ -79,14 +79,25 @@ func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory F } // append appends all the files from the supplied info to the corresponding files in this struct. -func (i *MonolithicHiddenAPIInfo) append(other *HiddenAPIInfo) { +func (i *MonolithicHiddenAPIInfo) append(ctx android.ModuleContext, otherModule android.Module, other *HiddenAPIInfo) { i.FlagsFilesByCategory.append(other.FlagFilesByCategory) i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPath) i.MetadataPaths = append(i.MetadataPaths, other.MetadataPath) i.IndexPaths = append(i.IndexPaths, other.IndexPath) - i.StubFlagSubsets = append(i.StubFlagSubsets, other.StubFlagSubset()) - i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset()) + apexInfo, ok := android.OtherModuleProvider(ctx, otherModule, android.ApexInfoProvider) + if !ok { + ctx.ModuleErrorf("Could not determine min_version_version of %s\n", otherModule.Name()) + return + } + if apexInfo.MinSdkVersion.LessThanOrEqualTo(android.ApiLevelR) { + // Restrict verify_overlaps to R and older modules. + // The runtime in S does not have the same restriction that + // requires the hiddenapi flags to be generated in a monolithic + // invocation. + i.StubFlagSubsets = append(i.StubFlagSubsets, other.StubFlagSubset()) + i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset()) + } } var MonolithicHiddenAPIInfoProvider = blueprint.NewProvider[MonolithicHiddenAPIInfo]()