diff options
author | 2025-03-20 16:11:36 -0700 | |
---|---|---|
committer | 2025-03-20 16:11:36 -0700 | |
commit | 29e0a00b2a9010b7b30f004fb9f6a2ad7ea20bcb (patch) | |
tree | cb888af41cf7962e5243791334e27beb1d7007b0 | |
parent | 36e0719e9ef8f0969254c7fd7aac355288e8e63e (diff) | |
parent | 8c31132dba8e206387296ec2a9d850832794d9b4 (diff) |
Snap for 13248265 from 8c31132dba8e206387296ec2a9d850832794d9b4 to 25Q2-release
Change-Id: If932ac6e530acdff73391ec4a2b3afb3a7adc401
-rw-r--r-- | aconfig/all_aconfig_declarations.go | 1 | ||||
-rw-r--r-- | android/Android.bp | 1 | ||||
-rw-r--r-- | android/configurable_properties.go | 3 | ||||
-rw-r--r-- | android/module.go | 8 | ||||
-rw-r--r-- | android/neverallow.go | 4 | ||||
-rw-r--r-- | android/otatools_package_cert_zip.go | 62 | ||||
-rw-r--r-- | android/selects_test.go | 78 | ||||
-rw-r--r-- | cc/fdo_profile.go | 9 | ||||
-rw-r--r-- | cmd/release_config/release_config_lib/release_configs.go | 3 | ||||
-rw-r--r-- | filesystem/android_device.go | 25 | ||||
-rw-r--r-- | filesystem/android_device_product_out.go | 2 | ||||
-rw-r--r-- | filesystem/avb_add_hash_footer.go | 7 | ||||
-rw-r--r-- | filesystem/filesystem.go | 17 | ||||
-rw-r--r-- | filesystem/system_other.go | 68 | ||||
-rw-r--r-- | filesystem/vbmeta.go | 54 | ||||
-rw-r--r-- | java/app.go | 3 | ||||
-rw-r--r-- | java/app_set.go | 7 | ||||
-rw-r--r-- | java/base.go | 2 | ||||
-rw-r--r-- | java/dex.go | 12 | ||||
-rw-r--r-- | java/dex_test.go | 2 | ||||
-rw-r--r-- | java/java.go | 4 | ||||
-rw-r--r-- | ui/build/finder.go | 33 |
22 files changed, 374 insertions, 31 deletions
diff --git a/aconfig/all_aconfig_declarations.go b/aconfig/all_aconfig_declarations.go index f3c68c37a..5a5262485 100644 --- a/aconfig/all_aconfig_declarations.go +++ b/aconfig/all_aconfig_declarations.go @@ -129,6 +129,7 @@ func (this *allAconfigDeclarationsSingleton) GenerateAndroidBuildActions(ctx and invalidExportedFlags := android.PathForIntermediates(ctx, "invalid_exported_flags.txt") GenerateExportedFlagCheck(ctx, invalidExportedFlags, parsedFlagsFile, this.properties) depsFiles = append(depsFiles, invalidExportedFlags) + ctx.Phony("droidcore", invalidExportedFlags) } } diff --git a/android/Android.bp b/android/Android.bp index 00dc50ac2..71e674767 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -83,6 +83,7 @@ bootstrap_go_package { "nothing.go", "notices.go", "onceper.go", + "otatools_package_cert_zip.go", "override_module.go", "package.go", "package_ctx.go", diff --git a/android/configurable_properties.go b/android/configurable_properties.go index 2c794a186..bde33e99b 100644 --- a/android/configurable_properties.go +++ b/android/configurable_properties.go @@ -7,7 +7,8 @@ import "github.com/google/blueprint/proptools" // to indicate a "default" case. func CreateSelectOsToBool(cases map[string]*bool) proptools.Configurable[bool] { var resultCases []proptools.ConfigurableCase[bool] - for pattern, value := range cases { + for _, pattern := range SortedKeys(cases) { + value := cases[pattern] if pattern == "" { resultCases = append(resultCases, proptools.NewConfigurableCase( []proptools.ConfigurablePattern{proptools.NewDefaultConfigurablePattern()}, diff --git a/android/module.go b/android/module.go index 87377cc75..ecd0f239c 100644 --- a/android/module.go +++ b/android/module.go @@ -22,6 +22,7 @@ import ( "reflect" "slices" "sort" + "strconv" "strings" "github.com/google/blueprint" @@ -2699,6 +2700,13 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu return proptools.ConfigurableValueString(v) case "bool": return proptools.ConfigurableValueBool(v == "true") + case "int": + i, err := strconv.ParseInt(v, 10, 64) + if err != nil { + ctx.OtherModulePropertyErrorf(m, property, "integer soong_config_variable was not an int: %q", v) + return proptools.ConfigurableValueUndefined() + } + return proptools.ConfigurableValueInt(i) case "string_list": return proptools.ConfigurableValueStringList(strings.Split(v, " ")) default: diff --git a/android/neverallow.go b/android/neverallow.go index e693f2ddd..98b443ee4 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -311,9 +311,9 @@ func createLimitGenruleRules() []Rule { "trusty_tee_package", // Trusty vm target names "trusty_desktop_vm_arm64.bin", - "trusty_desktop_vm_x86_64.elf", + "trusty_desktop_vm_x86_64.bin", "trusty_desktop_test_vm_arm64.bin", - "trusty_desktop_test_vm_x86_64.elf", + "trusty_desktop_test_vm_x86_64.bin", "trusty_test_vm_arm64.bin", "trusty_test_vm_x86_64.elf", "trusty_test_vm_os_arm64.bin", diff --git a/android/otatools_package_cert_zip.go b/android/otatools_package_cert_zip.go new file mode 100644 index 000000000..03265cad3 --- /dev/null +++ b/android/otatools_package_cert_zip.go @@ -0,0 +1,62 @@ +// Copyright 2025 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 android + +import ( + "github.com/google/blueprint" +) + +func init() { + RegisterOtatoolsPackageBuildComponents(InitRegistrationContext) + pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") +} + +func RegisterOtatoolsPackageBuildComponents(ctx RegistrationContext) { + ctx.RegisterModuleType("otatools_package_cert_files", OtatoolsPackageFactory) +} + +type OtatoolsPackage struct { + ModuleBase +} + +func OtatoolsPackageFactory() Module { + module := &OtatoolsPackage{} + InitAndroidModule(module) + return module +} + +var ( + otatoolsPackageCertRule = pctx.AndroidStaticRule("otatools_package_cert_files", blueprint.RuleParams{ + Command: "echo $out: > ${out}.d && cat $in >> ${out}.d && ${SoongZipCmd} -o $out -l $in", + CommandDeps: []string{"${SoongZipCmd}"}, + Depfile: "${out}.d", + Description: "Zip otatools-package cert files", + }) +) + +func (fg *OtatoolsPackage) GenerateAndroidBuildActions(ctx ModuleContext) { + if ctx.ModuleDir() != "build/make/tools/otatools_package" { + ctx.ModuleErrorf("There can only be one otatools_package_cert_files module in build/make/tools/otatools_package") + return + } + fileListFile := PathForArbitraryOutput(ctx, ".module_paths", "OtaToolsCertFiles.list") + otatoolsPackageCertZip := PathForModuleOut(ctx, "otatools_package_cert_files.zip") + ctx.Build(pctx, BuildParams{ + Rule: otatoolsPackageCertRule, + Input: fileListFile, + Output: otatoolsPackageCertZip, + }) + ctx.SetOutputFiles([]Path{otatoolsPackageCertZip}, "") +} diff --git a/android/selects_test.go b/android/selects_test.go index 7f20a3d66..8e469f8e3 100644 --- a/android/selects_test.go +++ b/android/selects_test.go @@ -666,6 +666,81 @@ func TestSelects(t *testing.T) { }, }, { + name: "Select on integer soong config variable", + bp: ` + my_module_type { + name: "foo", + my_string: select(soong_config_variable("my_namespace", "my_variable"), { + 34: "34", + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "34", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_string: proptools.StringPtr("34"), + }, + }, + { + name: "Select on integer soong config variable default", + bp: ` + my_module_type { + name: "foo", + my_string: select(soong_config_variable("my_namespace", "my_variable"), { + 34: "34", + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "5", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_string: proptools.StringPtr("other"), + }, + }, + { + name: "Assign to integer property", + bp: ` + my_module_type { + name: "foo", + my_int64: select(soong_config_variable("my_namespace", "my_variable"), { + any @ val: val, + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "5", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_int64: proptools.Int64Ptr(5), + }, + }, + { name: "Mismatched condition types", bp: ` my_module_type { @@ -1132,6 +1207,7 @@ my_module_type { type selectsTestProvider struct { my_bool *bool my_string *string + my_int64 *int64 my_string_list *[]string my_paths *[]string replacing_string_list *[]string @@ -1181,6 +1257,7 @@ var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]() type selectsMockModuleProperties struct { My_bool proptools.Configurable[bool] + My_int64 proptools.Configurable[int64] My_string proptools.Configurable[string] My_string_list proptools.Configurable[[]string] My_paths proptools.Configurable[[]string] `android:"path"` @@ -1213,6 +1290,7 @@ func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) { SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{ my_bool: optionalToPtr(p.properties.My_bool.Get(ctx)), my_string: optionalToPtr(p.properties.My_string.Get(ctx)), + my_int64: optionalToPtr(p.properties.My_int64.Get(ctx)), my_string_list: optionalToPtr(p.properties.My_string_list.Get(ctx)), my_paths: optionalToPtr(p.properties.My_paths.Get(ctx)), replacing_string_list: optionalToPtr(p.properties.Replacing_string_list.Get(ctx)), diff --git a/cc/fdo_profile.go b/cc/fdo_profile.go index 1a3395773..c79ea1018 100644 --- a/cc/fdo_profile.go +++ b/cc/fdo_profile.go @@ -17,6 +17,8 @@ package cc import ( "android/soong/android" "github.com/google/blueprint" + + "github.com/google/blueprint/proptools" ) func init() { @@ -34,7 +36,7 @@ type fdoProfile struct { } type fdoProfileProperties struct { - Profile *string `android:"arch_variant"` + Profile proptools.Configurable[string] `android:"arch_variant,replace_instead_of_append"` } // FdoProfileInfo is provided by FdoProfileProvider @@ -47,8 +49,9 @@ var FdoProfileProvider = blueprint.NewProvider[FdoProfileInfo]() // GenerateAndroidBuildActions of fdo_profile does not have any build actions func (fp *fdoProfile) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if fp.properties.Profile != nil { - path := android.PathForModuleSrc(ctx, *fp.properties.Profile) + profile := fp.properties.Profile.GetOrDefault(ctx, "") + if profile != "" { + path := android.PathForModuleSrc(ctx, profile) android.SetProvider(ctx, FdoProfileProvider, FdoProfileInfo{ Path: path, }) diff --git a/cmd/release_config/release_config_lib/release_configs.go b/cmd/release_config/release_config_lib/release_configs.go index b0f8cb7bf..dd98bca0b 100644 --- a/cmd/release_config/release_config_lib/release_configs.go +++ b/cmd/release_config/release_config_lib/release_configs.go @@ -314,6 +314,9 @@ func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex } } } + if flagDeclaration.Namespace == nil { + return fmt.Errorf("Flag declaration %s has no namespace.", path) + } m.FlagDeclarations = append(m.FlagDeclarations, *flagDeclaration) name := *flagDeclaration.Name diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 443e80e67..feb000dc4 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go @@ -840,6 +840,15 @@ func (a *androidDevice) addMiscInfo(ctx android.ModuleContext) android.Path { Textf("echo avb_enable=true >> %s", miscInfo). Textf("&& echo avb_building_vbmeta_image=true >> %s", miscInfo). Textf("&& echo avb_avbtool=avbtool >> %s", miscInfo) + for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions { + img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) + if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok { + builder.Command().Text("cat").Input(provider.PropFileForMiscInfo).Textf(" >> %s", miscInfo) + } else { + ctx.ModuleErrorf("vbmeta dep %s does not set vbmetaPartitionProvider\n", vbmetaPartitionName) + } + } + } if a.partitionProps.Boot_partition_name != nil { builder.Command().Textf("echo boot_images=boot.img >> %s", miscInfo) @@ -1046,6 +1055,7 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle } apkCerts := []string{} + var apkCertsFiles android.Paths for _, installedModule := range allInstalledModules { partition := "" if commonInfo, ok := android.OtherModuleProvider(ctx, installedModule, android.CommonModuleInfoProvider); ok { @@ -1054,7 +1064,11 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle ctx.ModuleErrorf("%s does not set CommonModuleInfoKey", installedModule.Name()) } if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfoProvider); ok { - apkCerts = append(apkCerts, formatLine(info.Certificate, info.InstallApkName+".apk", partition)) + if info.AppSet { + apkCertsFiles = append(apkCertsFiles, info.ApkCertsFile) + } else { + apkCerts = append(apkCerts, formatLine(info.Certificate, info.InstallApkName+".apk", partition)) + } } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfosProvider); ok { for _, certInfo := range info { // Partition information of apk-in-apex is not exported to the legacy Make packaging system. @@ -1075,7 +1089,14 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle } } + apkCertsInfoWithoutAppSets := android.PathForModuleOut(ctx, "apkcerts_without_app_sets.txt") + android.WriteFileRuleVerbatim(ctx, apkCertsInfoWithoutAppSets, strings.Join(apkCerts, "\n")+"\n") apkCertsInfo := android.PathForModuleOut(ctx, "apkcerts.txt") - android.WriteFileRuleVerbatim(ctx, apkCertsInfo, strings.Join(apkCerts, "\n")+"\n") + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cat, + Description: "combine apkcerts.txt", + Output: apkCertsInfo, + Inputs: append(apkCertsFiles, apkCertsInfoWithoutAppSets), + }) return apkCertsInfo } diff --git a/filesystem/android_device_product_out.go b/filesystem/android_device_product_out.go index 7d37f1ee7..aa06337ca 100644 --- a/filesystem/android_device_product_out.go +++ b/filesystem/android_device_product_out.go @@ -167,7 +167,7 @@ func (a *androidDevice) copyFilesToProductOutForSoongOnly(ctx android.ModuleCont } if proptools.String(a.deviceProps.Android_info) != "" { - installPath := android.PathForModuleInPartitionInstall(ctx, "", "android_info.txt") + installPath := android.PathForModuleInPartitionInstall(ctx, "", "android-info.txt") ctx.Build(pctx, android.BuildParams{ Rule: android.Cp, Input: android.PathForModuleSrc(ctx, *a.deviceProps.Android_info), diff --git a/filesystem/avb_add_hash_footer.go b/filesystem/avb_add_hash_footer.go index 327a41fda..c7760120d 100644 --- a/filesystem/avb_add_hash_footer.go +++ b/filesystem/avb_add_hash_footer.go @@ -70,7 +70,7 @@ type avbAddHashFooterProperties struct { Props []avbProp // The index used to prevent rollback of the image on device. - Rollback_index *int64 + Rollback_index proptools.Configurable[int64] `android:"replace_instead_of_append"` // Include descriptors from images Include_descriptors_from_images []string `android:"path,arch_variant"` @@ -134,8 +134,9 @@ func (a *avbAddHashFooter) GenerateAndroidBuildActions(ctx android.ModuleContext addAvbProp(ctx, cmd, prop) } - if a.properties.Rollback_index != nil { - rollbackIndex := proptools.Int(a.properties.Rollback_index) + rollbackIndex := a.properties.Rollback_index.Get(ctx) + if rollbackIndex.IsPresent() { + rollbackIndex := rollbackIndex.Get() if rollbackIndex < 0 { ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") } diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index f8faa496f..e86ebf4fa 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -455,6 +455,14 @@ type FilesystemInfo struct { HasFsverity bool PropFileForMiscInfo android.Path + + // Additional avb and partition size information. + // `system_other` will use this information of `system` dep for misc_info.txt processing. + PartitionSize *int64 + UseAvb bool + AvbAlgorithm string + AvbHashAlgorithm string + AvbKey android.Path } // FullInstallPathInfo contains information about the "full install" paths of all the files @@ -711,6 +719,15 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { Owners: f.gatherOwners(specs), HasFsverity: f.properties.Fsverity.Inputs.GetOrDefault(ctx, nil) != nil, PropFileForMiscInfo: propFileForMiscInfo, + PartitionSize: f.properties.Partition_size, + } + if proptools.Bool(f.properties.Use_avb) { + fsInfo.UseAvb = true + fsInfo.AvbAlgorithm = proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") + fsInfo.AvbHashAlgorithm = proptools.StringDefault(f.properties.Avb_hash_algorithm, "sha256") + if f.properties.Avb_private_key != nil { + fsInfo.AvbKey = android.PathForModuleSrc(ctx, *f.properties.Avb_private_key) + } } android.SetProvider(ctx, FilesystemProvider, fsInfo) diff --git a/filesystem/system_other.go b/filesystem/system_other.go index cbfd78b5b..32a6cc784 100644 --- a/filesystem/system_other.go +++ b/filesystem/system_other.go @@ -16,8 +16,11 @@ package filesystem import ( "android/soong/android" + "fmt" "path/filepath" + "sort" "strings" + "time" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -117,8 +120,11 @@ func (m *systemOtherImage) GenerateAndroidBuildActions(ctx android.ModuleContext // TOOD: CopySpecsToDir only exists on PackagingBase, but doesn't use any fields from it. Clean this up. (&android.PackagingBase{}).CopySpecsToDir(ctx, builder, specs, stagingDir) + fullInstallPaths := []string{} if len(m.properties.Preinstall_dexpreopt_files_from) > 0 { builder.Command().Textf("touch %s", filepath.Join(stagingDir.String(), "system-other-odex-marker")) + installPath := android.PathForModuleInPartitionInstall(ctx, "system_other", "system-other-odex-marker") + fullInstallPaths = append(fullInstallPaths, installPath.String()) } builder.Command().Textf("touch").Output(stagingDirTimestamp) builder.Build("assemble_filesystem_staging_dir", "Assemble filesystem staging dir") @@ -172,16 +178,21 @@ func (m *systemOtherImage) GenerateAndroidBuildActions(ctx android.ModuleContext builder.Build("build_system_other_hermetic", "build system other") fsInfo := FilesystemInfo{ - Output: output, - OutputHermetic: outputHermetic, - RootDir: stagingDir, - FilesystemConfig: m.generateFilesystemConfig(ctx, stagingDir, stagingDirTimestamp), + Output: output, + OutputHermetic: outputHermetic, + RootDir: stagingDir, + FilesystemConfig: m.generateFilesystemConfig(ctx, stagingDir, stagingDirTimestamp), + PropFileForMiscInfo: m.buildPropFileForMiscInfo(ctx), } android.SetProvider(ctx, FilesystemProvider, fsInfo) ctx.SetOutputFiles(android.Paths{output}, "") ctx.CheckbuildFile(output) + + // Dump compliance metadata + complianceMetadataInfo := ctx.ComplianceMetadataInfo() + complianceMetadataInfo.SetFilesContained(fullInstallPaths) } func (s *systemOtherImage) generateFilesystemConfig(ctx android.ModuleContext, stagingDir, stagingDirTimestamp android.Path) android.Path { @@ -204,3 +215,52 @@ func (f *systemOtherImage) propFileForHermeticImg(ctx android.ModuleContext, bui Textf(" && echo use_fixed_timestamp=true >> %s", propFilePinnedTimestamp) return propFilePinnedTimestamp } + +func (f *systemOtherImage) buildPropFileForMiscInfo(ctx android.ModuleContext) android.Path { + var lines []string + addStr := func(name string, value string) { + lines = append(lines, fmt.Sprintf("%s=%s", name, value)) + } + + addStr("building_system_other_image", "true") + + systemImage := ctx.GetDirectDepProxyWithTag(*f.properties.System_image, systemImageDependencyTag) + systemInfo, ok := android.OtherModuleProvider(ctx, systemImage, FilesystemProvider) + if !ok { + ctx.PropertyErrorf("system_image", "Expected system_image module to provide FilesystemProvider") + return nil + } + if systemInfo.PartitionSize == nil { + addStr("system_other_disable_sparse", "true") + } + if systemInfo.UseAvb { + addStr("avb_system_other_hashtree_enable", "true") + addStr("avb_system_other_algorithm", systemInfo.AvbAlgorithm) + footerArgs := fmt.Sprintf("--hash_algorithm %s", systemInfo.AvbHashAlgorithm) + if rollbackIndex, err := f.avbRollbackIndex(ctx); err == nil { + footerArgs += fmt.Sprintf(" --rollback_index %d", rollbackIndex) + } else { + ctx.ModuleErrorf("Could not determine rollback_index %s\n", err) + } + addStr("avb_system_other_add_hashtree_footer_args", footerArgs) + if systemInfo.AvbKey != nil { + addStr("avb_system_other_key_path", systemInfo.AvbKey.String()) + } + } + + sort.Strings(lines) + + propFile := android.PathForModuleOut(ctx, "prop_file") + android.WriteFileRule(ctx, propFile, strings.Join(lines, "\n")) + return propFile +} + +// Use the default: PlatformSecurityPatch +// TODO: Get this value from vbmeta_system +func (f *systemOtherImage) avbRollbackIndex(ctx android.ModuleContext) (int64, error) { + t, err := time.Parse(time.DateOnly, ctx.Config().PlatformSecurityPatch()) + if err != nil { + return -1, err + } + return t.Unix(), err +} diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go index 01b453e25..d59a2aec5 100644 --- a/filesystem/vbmeta.go +++ b/filesystem/vbmeta.go @@ -16,7 +16,10 @@ package filesystem import ( "fmt" + "sort" "strconv" + "strings" + "time" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -124,6 +127,10 @@ type vbmetaPartitionInfo struct { // The output of the vbmeta module Output android.Path + + // Information about the vbmeta partition that will be added to misc_info.txt + // created by android_device + PropFileForMiscInfo android.Path } var vbmetaPartitionProvider = blueprint.NewProvider[vbmetaPartitionInfo]() @@ -302,6 +309,7 @@ func (v *vbmeta) GenerateAndroidBuildActions(ctx android.ModuleContext) { RollbackIndexLocation: ril, PublicKey: extractedPublicKey, Output: output, + PropFileForMiscInfo: v.buildPropFileForMiscInfo(ctx), }) ctx.SetOutputFiles([]android.Path{output}, "") @@ -310,6 +318,41 @@ func (v *vbmeta) GenerateAndroidBuildActions(ctx android.ModuleContext) { setCommonFilesystemInfo(ctx, v) } +func (v *vbmeta) buildPropFileForMiscInfo(ctx android.ModuleContext) android.Path { + var lines []string + addStr := func(name string, value string) { + lines = append(lines, fmt.Sprintf("%s=%s", name, value)) + } + + addStr(fmt.Sprintf("avb_%s_algorithm", v.partitionName()), proptools.StringDefault(v.properties.Algorithm, "SHA256_RSA4096")) + if v.properties.Private_key != nil { + addStr(fmt.Sprintf("avb_%s_key_path", v.partitionName()), android.PathForModuleSrc(ctx, proptools.String(v.properties.Private_key)).String()) + } + if v.properties.Rollback_index_location != nil { + addStr(fmt.Sprintf("avb_%s_rollback_index_location", v.partitionName()), strconv.FormatInt(*v.properties.Rollback_index_location, 10)) + } + + var partitionDepNames []string + ctx.VisitDirectDepsProxyWithTag(vbmetaPartitionDep, func(child android.ModuleProxy) { + if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok { + partitionDepNames = append(partitionDepNames, info.Name) + } else { + ctx.ModuleErrorf("vbmeta dep %s does not set vbmetaPartitionProvider\n", child) + } + }) + if v.partitionName() != "vbmeta" { // skip for vbmeta to match Make's misc_info.txt + addStr(fmt.Sprintf("avb_%s", v.partitionName()), strings.Join(android.SortedUniqueStrings(partitionDepNames), " ")) + } + + addStr(fmt.Sprintf("avb_%s_args", v.partitionName()), fmt.Sprintf("--padding_size 4096 --rollback_index %s", v.rollbackIndexString(ctx))) + + sort.Strings(lines) + + propFile := android.PathForModuleOut(ctx, "prop_file_for_misc_info") + android.WriteFileRule(ctx, propFile, strings.Join(lines, "\n")) + return propFile +} + // Returns the embedded shell command that prints the rollback index func (v *vbmeta) rollbackIndexCommand(ctx android.ModuleContext) string { if v.properties.Rollback_index != nil { @@ -320,6 +363,17 @@ func (v *vbmeta) rollbackIndexCommand(ctx android.ModuleContext) string { } } +// Similar to rollbackIndexCommand, but guarantees that the rollback index is +// always computed during Soong analysis, even if v.properties.Rollback_index is nil +func (v *vbmeta) rollbackIndexString(ctx android.ModuleContext) string { + if v.properties.Rollback_index != nil { + return fmt.Sprintf("%d", *v.properties.Rollback_index) + } else { + t, _ := time.Parse(time.DateOnly, ctx.Config().PlatformSecurityPatch()) + return fmt.Sprintf("%d", t.Unix()) + } +} + var _ android.AndroidMkProviderInfoProducer = (*vbmeta)(nil) func (v *vbmeta) PrepareAndroidMKProviderInfo(config android.Config) *android.AndroidMkProviderInfo { diff --git a/java/app.go b/java/app.go index 553c65894..05b4a9664 100644 --- a/java/app.go +++ b/java/app.go @@ -82,6 +82,7 @@ type AppInfo struct { Certificate Certificate PrivAppAllowlist android.OptionalPath OverriddenManifestPackageName *string + ApkCertsFile android.Path } var AppInfoProvider = blueprint.NewProvider[*AppInfo]() @@ -691,7 +692,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { } // Use non final ids if we are doing optimized shrinking and are using R8. - nonFinalIds := a.dexProperties.optimizedResourceShrinkingEnabled(ctx) && a.dexer.effectiveOptimizeEnabled() + nonFinalIds := a.dexProperties.optimizedResourceShrinkingEnabled(ctx) && a.dexer.effectiveOptimizeEnabled(ctx) aconfigTextFilePaths := getAconfigFilePaths(ctx) diff --git a/java/app_set.go b/java/app_set.go index 2e9d31410..6a2c678a8 100644 --- a/java/app_set.go +++ b/java/app_set.go @@ -193,9 +193,10 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) ) android.SetProvider(ctx, AppInfoProvider, &AppInfo{ - AppSet: true, - Privileged: as.Privileged(), - OutputFile: as.OutputFile(), + AppSet: true, + Privileged: as.Privileged(), + OutputFile: as.OutputFile(), + ApkCertsFile: as.apkcertsFile, }) } diff --git a/java/base.go b/java/base.go index 1a12075bc..8aa0109d0 100644 --- a/java/base.go +++ b/java/base.go @@ -1816,7 +1816,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath classesJar: outputFile, jarName: jarName, } - if j.GetProfileGuided(ctx) && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting(ctx) { + if j.GetProfileGuided(ctx) && j.optimizeOrObfuscateEnabled(ctx) && !j.EnableProfileRewriting(ctx) { ctx.PropertyErrorf("enable_profile_rewriting", "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on. The attached profile should be sourced from an unoptimized/unobfuscated APK.", ) diff --git a/java/dex.go b/java/dex.go index ed9c82ba2..dd6467546 100644 --- a/java/dex.go +++ b/java/dex.go @@ -161,8 +161,8 @@ type dexer struct { providesTransitiveHeaderJarsForR8 } -func (d *dexer) effectiveOptimizeEnabled() bool { - return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault) +func (d *dexer) effectiveOptimizeEnabled(ctx android.EarlyModuleContext) bool { + return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault && !ctx.Config().Eng()) } func (d *DexProperties) resourceShrinkingEnabled(ctx android.ModuleContext) bool { @@ -173,8 +173,8 @@ func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleCont return d.resourceShrinkingEnabled(ctx) && BoolDefault(d.Optimize.Optimized_shrink_resources, ctx.Config().UseOptimizedResourceShrinkingByDefault()) } -func (d *dexer) optimizeOrObfuscateEnabled() bool { - return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) +func (d *dexer) optimizeOrObfuscateEnabled(ctx android.EarlyModuleContext) bool { + return d.effectiveOptimizeEnabled(ctx) && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) } var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", @@ -353,7 +353,7 @@ func (d *dexer) dexCommonFlags(ctx android.ModuleContext, flags = append(flags, "--release") } else if ctx.Config().Eng() { flags = append(flags, "--debug") - } else if !d.effectiveOptimizeEnabled() && d.dexProperties.Optimize.EnabledByDefault { + } else if !d.effectiveOptimizeEnabled(ctx) && d.dexProperties.Optimize.EnabledByDefault { // D8 uses --debug by default, whereas R8 uses --release by default. // For targets that default to R8 usage (e.g., apps), but override this default, we still // want D8 to run in release mode, preserving semantics as much as possible between the two. @@ -627,7 +627,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins" } - useR8 := d.effectiveOptimizeEnabled() + useR8 := d.effectiveOptimizeEnabled(ctx) useD8 := !useR8 || ctx.Config().PartialCompileFlags().Use_d8 rbeR8 := ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") rbeD8 := ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") diff --git a/java/dex_test.go b/java/dex_test.go index e94864bbc..8c1e5f7df 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -797,12 +797,14 @@ func TestDebugReleaseFlags(t *testing.T) { }, { name: "app_eng", + useD8: true, isEng: true, expectedFlags: "--debug", }, { name: "app_release_eng", isEng: true, + useD8: true, dxFlags: "--release", // Eng mode does *not* override explicit dxflags. expectedFlags: "--release", diff --git a/java/java.go b/java/java.go index dd9f852f0..07e38a17e 100644 --- a/java/java.go +++ b/java/java.go @@ -670,12 +670,12 @@ func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...) - if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() { + if d.effectiveOptimizeEnabled(ctx) && sdkDep.hasStandardLibs() { ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries..., ) } - if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() { + if d.effectiveOptimizeEnabled(ctx) && sdkDep.hasFrameworkLibs() { ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...) } } diff --git a/ui/build/finder.go b/ui/build/finder.go index 783b48863..ff8908b29 100644 --- a/ui/build/finder.go +++ b/ui/build/finder.go @@ -84,8 +84,14 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { // METADATA file of packages "METADATA", }, - // .mk files for product/board configuration. - IncludeSuffixes: []string{".mk"}, + IncludeSuffixes: []string{ + // .mk files for product/board configuration. + ".mk", + // otatools cert files + ".pk8", + ".pem", + ".avbpubkey", + }, } dumpDir := config.FileListDir() f, err = finder.New(cacheParams, filesystem, logger.New(ioutil.Discard), @@ -118,6 +124,18 @@ func findProductAndBoardConfigFiles(entries finder.DirEntries) (dirNames []strin return entries.DirNames, matches } +func findOtaToolsCertFiles(entries finder.DirEntries) (dirNames []string, fileNames []string) { + matches := []string{} + for _, foundName := range entries.FileNames { + if strings.HasSuffix(foundName, ".pk8") || + strings.HasSuffix(foundName, ".pem") || + strings.HasSuffix(foundName, ".avbpubkey") { + matches = append(matches, foundName) + } + } + return entries.DirNames, matches +} + // FindSources searches for source files known to <f> and writes them to the filesystem for // use later. func FindSources(ctx Context, config Config, f *finder.Finder) { @@ -184,6 +202,17 @@ func FindSources(ctx Context, config Config, f *finder.Finder) { ctx.Fatalf("Could not find TEST_MAPPING: %v", err) } + // Recursively look for all otatools cert files. + otatools_cert_files := f.FindMatching("build/make/target/product/security", findOtaToolsCertFiles) + otatools_cert_files = append(otatools_cert_files, f.FindMatching("device", findOtaToolsCertFiles)...) + otatools_cert_files = append(otatools_cert_files, f.FindMatching("external/avb/test/data", findOtaToolsCertFiles)...) + otatools_cert_files = append(otatools_cert_files, f.FindMatching("packages/modules", findOtaToolsCertFiles)...) + otatools_cert_files = append(otatools_cert_files, f.FindMatching("vendor", findOtaToolsCertFiles)...) + err = dumpListToFile(ctx, config, otatools_cert_files, filepath.Join(dumpDir, "OtaToolsCertFiles.list")) + if err != nil { + ctx.Fatalf("Could not find otatools cert files: %v", err) + } + // Recursively look for all Android.bp files androidBps := f.FindNamedAt(".", "Android.bp") if len(androidBps) == 0 { |