diff options
author | 2025-03-05 23:27:55 +0000 | |
---|---|---|
committer | 2025-03-06 21:48:42 +0000 | |
commit | 38afe711d13e01ca1d5db96dd018a1044ee4f3aa (patch) | |
tree | 4e9f1aac67e202d6751db6884bc4272301181b84 /filesystem/android_device.go | |
parent | 31769efdc845e1f89a4d397ad103566e03bee176 (diff) |
Create apkcerts.txt using Soong
This CL creates an apkcerts.txt of the apps installed on the device, and
any apk-in-apex of installed apexes. Note that this behavior is unlike
make. There is some ongoing discussion on whether the make behavior can
be updated to only list the installed apps as well.
To implement this, androidDevice will consult the following providers
from the list of installed modules
- AppInfoProvider (android_app, android_app_import, ...)
- AppInfosProvider (for apk-in-apex)
- RuntimeResourceOverlayInfoProvider (for checked-in and autogen rros)
Test: With https://r.android.com/3529333, apkcerts.txt is identical for
aosp_cf_x86_64_phone between make and soong
Bug: 399788149
Change-Id: I10009ea8761a197dd2301acf9615079bd28af3f5
Diffstat (limited to 'filesystem/android_device.go')
-rw-r--r-- | filesystem/android_device.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 3d306e365..17209ed4a 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go @@ -114,6 +114,7 @@ type androidDevice struct { miscInfo android.Path rootDirForFsConfig string rootDirForFsConfigTimestamp android.Path + apkCertsInfo android.Path } func AndroidDeviceFactory() android.Module { @@ -188,6 +189,7 @@ func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { allInstalledModules := a.allInstalledModules(ctx) + a.apkCertsInfo = a.buildApkCertsInfo(ctx, allInstalledModules) a.kernelConfig, a.kernelVersion = a.extractKernelVersionAndConfigs(ctx) a.miscInfo = a.addMiscInfo(ctx) a.buildTargetFilesZip(ctx, allInstalledModules) @@ -651,6 +653,9 @@ func (a *androidDevice) copyMetadataToTargetZip(ctx android.ModuleContext, build } installedApexKeys = android.SortedUniquePaths(installedApexKeys) // Sort by keypath to match make builder.Command().Text("cat").Inputs(installedApexKeys).Textf(" >> %s/META/apexkeys.txt", targetFilesDir.String()) + // apkcerts.txt + builder.Command().Textf("cp").Input(a.apkCertsInfo).Textf(" %s/META/", targetFilesDir.String()) + // Copy fastboot-info.txt if fastbootInfo := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.FastbootInfo)); fastbootInfo != nil { // TODO (b/399788523): Autogenerate fastboot-info.txt if there is no source fastboot-info.txt @@ -864,3 +869,49 @@ func (a *androidDevice) extractKernelVersionAndConfigs(ctx android.ModuleContext return extractedVersionFile, extractedConfigsFile } + +func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalledModules []android.Module) android.Path { + // TODO (spandandas): Add compressed + formatLine := func(cert java.Certificate, name, partition string) string { + pem := cert.AndroidMkString() + var key string + if cert.Key == nil { + key = "" + } else { + key = cert.Key.String() + } + return fmt.Sprintf(`name="%s" certificate="%s" private_key="%s" partition="%s"`, name, pem, key, partition) + } + + apkCerts := []string{} + for _, installedModule := range allInstalledModules { + partition := "" + if commonInfo, ok := android.OtherModuleProvider(ctx, installedModule, android.CommonModuleInfoKey); ok { + partition = commonInfo.PartitionTag + } else { + 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)) + } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfosProvider); ok { + for _, certInfo := range info { + apkCerts = append(apkCerts, formatLine(certInfo.Certificate, certInfo.InstallApkName+".apk", partition)) + } + } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.RuntimeResourceOverlayInfoProvider); ok { + apkCerts = append(apkCerts, formatLine(info.Certificate, info.OutputFile.Base(), partition)) + } + } + slices.Sort(apkCerts) // sort by name + fsInfos := a.getFsInfos(ctx) + if fsInfos["system"].HasFsverity { + defaultPem, defaultKey := ctx.Config().DefaultAppCertificate(ctx) + apkCerts = append(apkCerts, formatLine(java.Certificate{Pem: defaultPem, Key: defaultKey}, "BuildManifest.apk", "system")) + if info, ok := fsInfos["system_ext"]; ok && info.HasFsverity { + apkCerts = append(apkCerts, formatLine(java.Certificate{Pem: defaultPem, Key: defaultKey}, "BuildManifestSystemExt.apk", "system_ext")) + } + } + + apkCertsInfo := android.PathForModuleOut(ctx, "apkcerts.txt") + android.WriteFileRuleVerbatim(ctx, apkCertsInfo, strings.Join(apkCerts, "\n")+"\n") + return apkCertsInfo +} |