Propagate permitted packages to sdk snapshot
Previously, permitted_packages were not copied to the sdk snapshot.
This change corrects that.
Bug: 193763688
Test: m nothing
- Added unit tests, which all failed and then fixed the tests.
Merged-In: I4560987f746f78c0ae706058195b6db4bea438aa
Change-Id: I4560987f746f78c0ae706058195b6db4bea438aa
(cherry picked from commit 869de147abdb2c86a91cced4fda7d27746c52af4)
diff --git a/java/java.go b/java/java.go
index ca63782..727cef5 100644
--- a/java/java.go
+++ b/java/java.go
@@ -581,6 +581,10 @@
JarToExport android.Path `android:"arch_variant"`
AidlIncludeDirs android.Paths
+
+ // The list of permitted packages that need to be passed to the prebuilts as they are used to
+ // create the updatable-bcp-packages.txt file.
+ PermittedPackages []string
}
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
@@ -589,6 +593,8 @@
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
p.AidlIncludeDirs = j.AidlIncludeDirs()
+
+ p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars()
}
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
@@ -607,6 +613,10 @@
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
+ if len(p.PermittedPackages) > 0 {
+ propertySet.AddProperty("permitted_packages", p.PermittedPackages)
+ }
+
// Do not copy anything else to the snapshot.
if memberType.onlyCopyJarToSnapshot {
return
@@ -1127,6 +1137,10 @@
Installable *bool
+ // If not empty, classes are restricted to the specified packages and their sub-packages.
+ // This information is used to generate the updatable-bcp-packages.txt file.
+ Permitted_packages []string
+
// List of shared java libs that this module has dependencies to
Libs []string
diff --git a/java/sdk_library.go b/java/sdk_library.go
index f2d0c59..c0e5662 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1893,6 +1893,10 @@
// If set to true, compile dex files for the stubs. Defaults to false.
Compile_dex *bool
+
+ // If not empty, classes are restricted to the specified packages and their sub-packages.
+ // This information is used to generate the updatable-bcp-packages.txt file.
+ Permitted_packages []string
}
type SdkLibraryImport struct {
@@ -2506,6 +2510,8 @@
// The paths to the doctag files to add to the prebuilt.
Doctag_paths android.Paths
+
+ Permitted_packages []string
}
type scopeProperties struct {
@@ -2546,6 +2552,7 @@
s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary())
s.Compile_dex = sdk.dexProperties.Compile_dex
s.Doctag_paths = sdk.doctagPaths
+ s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars()
}
func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
@@ -2558,6 +2565,9 @@
if s.Compile_dex != nil {
propertySet.AddProperty("compile_dex", *s.Compile_dex)
}
+ if len(s.Permitted_packages) > 0 {
+ propertySet.AddProperty("permitted_packages", s.Permitted_packages)
+ }
for _, apiScope := range allApiScopes {
if properties, ok := s.Scopes[apiScope]; ok {
diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go
index 9b7b868..c30324a 100644
--- a/sdk/bootclasspath_fragment_sdk_test.go
+++ b/sdk/bootclasspath_fragment_sdk_test.go
@@ -346,6 +346,7 @@
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: ["java/mybootlib.jar"],
+ permitted_packages: ["mybootlib"],
}
java_sdk_library_import {
@@ -355,6 +356,7 @@
apex_available: ["myapex"],
shared_library: true,
compile_dex: true,
+ permitted_packages: ["myothersdklibrary"],
public: {
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
@@ -428,6 +430,7 @@
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: ["java/mybootlib.jar"],
+ permitted_packages: ["mybootlib"],
}
java_sdk_library_import {
@@ -437,6 +440,7 @@
apex_available: ["myapex"],
shared_library: true,
compile_dex: true,
+ permitted_packages: ["myothersdklibrary"],
public: {
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
@@ -677,6 +681,7 @@
srcs: ["Test.java"],
compile_dex: true,
public: {enabled: true},
+ permitted_packages: ["mysdklibrary"],
}
`),
).RunTest(t)
@@ -720,6 +725,7 @@
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: ["java/mybootlib.jar"],
+ permitted_packages: ["mybootlib"],
}
java_sdk_library_import {
@@ -729,6 +735,7 @@
apex_available: ["//apex_available:platform"],
shared_library: true,
compile_dex: true,
+ permitted_packages: ["mysdklibrary"],
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index a2cfe6d..813dcfd 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -175,6 +175,7 @@
sdk_version: "none",
compile_dex: true,
host_supported: true,
+ permitted_packages: ["pkg.myjavalib"],
}
`)
@@ -188,6 +189,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
}
`),
checkVersionedAndroidBpContents(`
@@ -199,6 +201,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
}
sdk_snapshot {
@@ -437,6 +440,7 @@
system_modules: "none",
sdk_version: "none",
compile_dex: true,
+ permitted_packages: ["pkg.myjavalib"],
}
`)
@@ -450,6 +454,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
}
`),
checkVersionedAndroidBpContents(`
@@ -461,6 +466,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
}
module_exports_snapshot {
@@ -1045,6 +1051,7 @@
shared_library: false,
stubs_library_visibility: ["//other"],
stubs_source_visibility: ["//another"],
+ permitted_packages: ["pkg.myjavalib"],
}
`)
@@ -1058,6 +1065,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: false,
+ permitted_packages: ["pkg.myjavalib"],
public: {
jars: ["sdk_library/public/myjavalib-stubs.jar"],
stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
@@ -1090,6 +1098,7 @@
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: false,
+ permitted_packages: ["pkg.myjavalib"],
public: {
jars: ["sdk_library/public/myjavalib-stubs.jar"],
stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],