Merge Android R

Bug: 168057903
Merged-In: I9d5d0da0f409bd6b131f7e0f6363be061d3045c1
Change-Id: Ie7feaf6a3d0787c750de17540969b876a4306b0a
This commit is contained in:
Xin Li
2020-09-09 20:21:02 -07:00
19 changed files with 667 additions and 148 deletions

View File

@@ -108,6 +108,9 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
}
fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
if fi.module != nil && fi.module.Owner() != "" {
fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner())
}
// /apex/<apex_name>/{lib|framework|...}
pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
var modulePath string

View File

@@ -100,6 +100,13 @@ func makeApexAvailableBaseline() map[string][]string {
//
// Module separator
//
m["com.android.appsearch"] = []string{
"icing-java-proto-lite",
"libprotobuf-java-lite",
}
//
// Module separator
//
m["com.android.bluetooth.updatable"] = []string{
"android.hardware.audio.common@5.0",
"android.hardware.bluetooth.a2dp@1.0",
@@ -182,6 +189,19 @@ func makeApexAvailableBaseline() map[string][]string {
//
// Module separator
//
m["com.android.extservices"] = []string{
"error_prone_annotations",
"ExtServices-core",
"ExtServices",
"libtextclassifier-java",
"libz_current",
"textclassifier-statsd",
"TextClassifierNotificationLibNoManifest",
"TextClassifierServiceLibNoManifest",
}
//
// Module separator
//
m["com.android.neuralnetworks"] = []string{
"android.hardware.neuralnetworks@1.0",
"android.hardware.neuralnetworks@1.1",
@@ -297,7 +317,6 @@ func makeApexAvailableBaseline() map[string][]string {
"libpdx_headers",
"libpdx_uds",
"libprocinfo",
"libsonivox",
"libspeexresampler",
"libspeexresampler",
"libstagefright_esds",
@@ -334,6 +353,7 @@ func makeApexAvailableBaseline() map[string][]string {
"android.hardware.configstore@1.1",
"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-ndk_platform",
@@ -346,6 +366,7 @@ func makeApexAvailableBaseline() map[string][]string {
"android.hardware.graphics.mapper@4.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.hardware.media@1.0",
"android.hardware.media@1.0",
@@ -439,6 +460,7 @@ func makeApexAvailableBaseline() map[string][]string {
"libpdx_headers",
"libscudo_wrapper",
"libsfplugin_ccodec_utils",
"libspeexresampler",
"libstagefright_amrnb_common",
"libstagefright_amrnbdec",
"libstagefright_amrnbenc",
@@ -481,6 +503,8 @@ func makeApexAvailableBaseline() map[string][]string {
// Module separator
//
m["com.android.permission"] = []string{
"car-ui-lib",
"iconloader",
"kotlin-annotations",
"kotlin-stdlib",
"kotlin-stdlib-jdk7",
@@ -490,6 +514,17 @@ func makeApexAvailableBaseline() map[string][]string {
"kotlinx-coroutines-core",
"kotlinx-coroutines-core-nodeps",
"permissioncontroller-statsd",
"GooglePermissionController",
"PermissionController",
"SettingsLibActionBarShadow",
"SettingsLibAppPreference",
"SettingsLibBarChartPreference",
"SettingsLibLayoutPreference",
"SettingsLibProgressBar",
"SettingsLibSearchWidget",
"SettingsLibSettingsTheme",
"SettingsLibRestrictedLockUtils",
"SettingsLibHelpUtils",
}
//
// Module separator
@@ -648,6 +683,55 @@ func makeApexAvailableBaseline() map[string][]string {
return m
}
// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
// Adding code to the bootclasspath in new packages will cause issues on module update.
func qModulesPackages() map[string][]string {
return map[string][]string{
"com.android.conscrypt": []string{
"android.net.ssl",
"com.android.org.conscrypt",
},
"com.android.media": []string{
"android.media",
},
}
}
// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
// Adding code to the bootclasspath in new packages will cause issues on module update.
func rModulesPackages() map[string][]string {
return map[string][]string{
"com.android.mediaprovider": []string{
"android.provider",
},
"com.android.permission": []string{
"android.permission",
"android.app.role",
"com.android.permission",
"com.android.role",
},
"com.android.sdkext": []string{
"android.os.ext",
},
"com.android.os.statsd": []string{
"android.app",
"android.os",
"android.util",
"com.android.internal.statsd",
"com.android.server.stats",
},
"com.android.wifi": []string{
"com.android.server.wifi",
"com.android.wifi.x",
"android.hardware.wifi",
"android.net.wifi",
},
"com.android.tethering": []string{
"android.net",
},
}
}
func init() {
android.RegisterModuleType("apex", BundleFactory)
android.RegisterModuleType("apex_test", testApexBundleFactory)
@@ -665,6 +749,24 @@ func init() {
sort.Strings(*apexFileContextsInfos)
ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
})
android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
}
func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
rules := make([]android.Rule, 0, len(modules_packages))
for module_name, module_packages := range modules_packages {
permitted_packages_rule := android.NeverAllow().
BootclasspathJar().
With("apex_available", module_name).
WithMatcher("permitted_packages", android.NotInList(module_packages)).
Because("jars that are part of the " + module_name +
" module may only allow these packages: " + strings.Join(module_packages, ",") +
". Please jarjar or move code around.")
rules = append(rules, permitted_packages_rule)
}
return rules
}
func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
@@ -1971,13 +2073,6 @@ func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext
return false
}
// TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
// is capable of providing a stub variant, but is being statically linked from the bluetooth
// APEX.
if toName == "libstatssocket" {
return false
}
// The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
// It can't make the static dependencies dynamic because it can't
// do the dynamic linking for itself.

View File

@@ -5740,6 +5740,141 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
})
}
func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) {
t.Helper()
android.ClearApexDependency()
bp += `
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}`
fs := map[string][]byte{
"lib1/src/A.java": nil,
"lib2/src/B.java": nil,
"system/sepolicy/apex/myapex-file_contexts": nil,
}
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("apex", BundleFactory)
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
cc.RegisterRequiredBuildComponentsForTest(ctx)
java.RegisterJavaBuildComponents(ctx)
java.RegisterSystemModulesBuildComponents(ctx)
java.RegisterDexpreoptBootJarsComponents(ctx)
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
ctx.PostDepsMutators(android.RegisterNeverallowMutator)
config := android.TestArchConfig(buildDir, nil, bp, fs)
android.SetTestNeverallowRules(config, rules)
updatableBootJars := make([]string, 0, len(apexBootJars))
for _, apexBootJar := range apexBootJars {
updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
}
config.TestProductVariables.UpdatableBootJars = updatableBootJars
ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
if errmsg == "" {
android.FailIfErrored(t, errs)
} else if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, errmsg, errs)
return
} else {
t.Fatalf("missing expected error %q (0 errors are returned)", errmsg)
}
}
func TestApexPermittedPackagesRules(t *testing.T) {
testcases := []struct {
name string
expectedError string
bp string
bootJars []string
modulesPackages map[string][]string
}{
{
name: "Non-Bootclasspath apex jar not satisfying allowed module packages.",
expectedError: "",
bp: `
java_library {
name: "bcp_lib1",
srcs: ["lib1/src/*.java"],
permitted_packages: ["foo.bar"],
apex_available: ["myapex"],
sdk_version: "none",
system_modules: "none",
}
java_library {
name: "nonbcp_lib2",
srcs: ["lib2/src/*.java"],
apex_available: ["myapex"],
permitted_packages: ["a.b"],
sdk_version: "none",
system_modules: "none",
}
apex {
name: "myapex",
key: "myapex.key",
java_libs: ["bcp_lib1", "nonbcp_lib2"],
}`,
bootJars: []string{"bcp_lib1"},
modulesPackages: map[string][]string{
"myapex": []string{
"foo.bar",
},
},
},
{
name: "Bootclasspath apex jar not satisfying allowed module packages.",
expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`,
bp: `
java_library {
name: "bcp_lib1",
srcs: ["lib1/src/*.java"],
apex_available: ["myapex"],
permitted_packages: ["foo.bar"],
sdk_version: "none",
system_modules: "none",
}
java_library {
name: "bcp_lib2",
srcs: ["lib2/src/*.java"],
apex_available: ["myapex"],
permitted_packages: ["foo.bar", "bar.baz"],
sdk_version: "none",
system_modules: "none",
}
apex {
name: "myapex",
key: "myapex.key",
java_libs: ["bcp_lib1", "bcp_lib2"],
}
`,
bootJars: []string{"bcp_lib1", "bcp_lib2"},
modulesPackages: map[string][]string{
"myapex": []string{
"foo.bar",
},
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
rules := createApexPermittedPackagesRules(tc.modulesPackages)
testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules)
})
}
}
func TestTestFor(t *testing.T) {
ctx, _ := testApex(t, `
apex {
@@ -5807,8 +5942,10 @@ func TestApexSet(t *testing.T) {
}
`, func(fs map[string][]byte, config android.Config) {
config.TestProductVariables.Platform_sdk_version = intPtr(30)
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm")
config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm64")
config.Targets[android.Android] = []android.Target{
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}},
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}},
}
})
m := ctx.ModuleForTests("myapex", "android_common")

View File

@@ -690,7 +690,7 @@ func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
apexBundleName := a.Name()
a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
if a.installable() && a.GetOverriddenBy() == "" {
if a.installable() {
installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())

View File

@@ -257,6 +257,9 @@ type ApexSet struct {
// list of commands to create symlinks for backward compatibility.
// these commands will be attached as LOCAL_POST_INSTALL_CMD
compatSymlinks []string
hostRequired []string
postInstallCommands []string
}
type ApexSetProperties struct {
@@ -343,21 +346,43 @@ func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
for _, overridden := range a.properties.Overrides {
a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
}
if ctx.Config().InstallExtraFlattenedApexes() {
// flattened apex should be in /system_ext/apex
flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName())
a.postInstallCommands = append(a.postInstallCommands,
fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s",
a.outputApex.String(),
flattenedApexDir.ToMakePath().String(),
))
a.hostRequired = []string{"deapexer", "debugfs"}
}
}
type systemExtContext struct {
android.ModuleContext
}
func (*systemExtContext) SystemExtSpecific() bool {
return true
}
func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "ETC",
OutputFile: android.OptionalPathForPath(a.outputApex),
Include: "$(BUILD_PREBUILT)",
Class: "ETC",
OutputFile: android.OptionalPathForPath(a.outputApex),
Include: "$(BUILD_PREBUILT)",
Host_required: a.hostRequired,
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String())
entries.SetString("LOCAL_MODULE_STEM", a.installFilename)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable())
entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...)
if len(a.compatSymlinks) > 0 {
entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(a.compatSymlinks, " && "))
postInstallCommands := append([]string{}, a.postInstallCommands...)
postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
if len(postInstallCommands) > 0 {
entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
}
},
},