Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | // This file contains the module implementations for runtime_resource_overlay and |
| 18 | // override_runtime_resource_overlay. |
| 19 | |
Cole Faust | b749347 | 2024-08-28 11:55:52 -0700 | [diff] [blame] | 20 | import ( |
| 21 | "android/soong/android" |
| 22 | |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Cole Faust | b749347 | 2024-08-28 11:55:52 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 26 | |
| 27 | func init() { |
| 28 | RegisterRuntimeResourceOverlayBuildComponents(android.InitRegistrationContext) |
| 29 | } |
| 30 | |
| 31 | func RegisterRuntimeResourceOverlayBuildComponents(ctx android.RegistrationContext) { |
| 32 | ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory) |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 33 | ctx.RegisterModuleType("autogen_runtime_resource_overlay", AutogenRuntimeResourceOverlayFactory) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 34 | ctx.RegisterModuleType("override_runtime_resource_overlay", OverrideRuntimeResourceOverlayModuleFactory) |
| 35 | } |
| 36 | |
Yu Liu | 0a37d42 | 2025-02-13 02:05:00 +0000 | [diff] [blame] | 37 | type RuntimeResourceOverlayInfo struct { |
| 38 | OutputFile android.Path |
| 39 | Certificate Certificate |
| 40 | Theme string |
| 41 | OverriddenManifestPackageName string |
| 42 | } |
| 43 | |
| 44 | var RuntimeResourceOverlayInfoProvider = blueprint.NewProvider[RuntimeResourceOverlayInfo]() |
| 45 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 46 | type RuntimeResourceOverlay struct { |
| 47 | android.ModuleBase |
| 48 | android.DefaultableModuleBase |
| 49 | android.OverridableModuleBase |
| 50 | aapt |
| 51 | |
| 52 | properties RuntimeResourceOverlayProperties |
| 53 | overridableProperties OverridableRuntimeResourceOverlayProperties |
| 54 | |
| 55 | certificate Certificate |
| 56 | |
| 57 | outputFile android.Path |
| 58 | installDir android.InstallPath |
| 59 | } |
| 60 | |
| 61 | type RuntimeResourceOverlayProperties struct { |
| 62 | // the name of a certificate in the default certificate directory or an android_app_certificate |
| 63 | // module name in the form ":module". |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 64 | Certificate proptools.Configurable[string] `android:"replace_instead_of_append"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 65 | |
| 66 | // Name of the signing certificate lineage file. |
| 67 | Lineage *string |
| 68 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 69 | // For overriding the --rotation-min-sdk-version property of apksig |
| 70 | RotationMinSdkVersion *string |
| 71 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 72 | // optional theme name. If specified, the overlay package will be applied |
| 73 | // only when the ro.boot.vendor.overlay.theme system property is set to the same value. |
| 74 | Theme *string |
| 75 | |
Tobias Thierer | 1b3e949 | 2021-01-02 19:01:16 +0000 | [diff] [blame] | 76 | // If not blank, set to the version of the sdk to compile against. This |
| 77 | // can be either an API version (e.g. "29" for API level 29 AKA Android 10) |
| 78 | // or special subsets of the current platform, for example "none", "current", |
| 79 | // "core", "system", "test". See build/soong/java/sdk.go for the full and |
| 80 | // up-to-date list of possible values. |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 81 | // Defaults to compiling against the current platform. |
| 82 | Sdk_version *string |
| 83 | |
| 84 | // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 85 | // Defaults to sdk_version if not set. |
| 86 | Min_sdk_version *string |
| 87 | |
| 88 | // list of android_library modules whose resources are extracted and linked against statically |
Cole Faust | b749347 | 2024-08-28 11:55:52 -0700 | [diff] [blame] | 89 | Static_libs proptools.Configurable[[]string] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 90 | |
| 91 | // list of android_app modules whose resources are extracted and linked against |
| 92 | Resource_libs []string |
| 93 | |
| 94 | // Names of modules to be overridden. Listed modules can only be other overlays |
| 95 | // (in Make or Soong). |
| 96 | // This does not completely prevent installation of the overridden overlays, but if both |
| 97 | // overlays would be installed by default (in PRODUCT_PACKAGES) the other overlay will be removed |
| 98 | // from PRODUCT_PACKAGES. |
| 99 | Overrides []string |
| 100 | } |
| 101 | |
| 102 | // RuntimeResourceOverlayModule interface is used by the apex package to gather information from |
| 103 | // a RuntimeResourceOverlay module. |
| 104 | type RuntimeResourceOverlayModule interface { |
| 105 | android.Module |
| 106 | OutputFile() android.Path |
| 107 | Certificate() Certificate |
| 108 | Theme() string |
| 109 | } |
| 110 | |
Spandan Das | 5d1b929 | 2021-06-03 19:36:41 +0000 | [diff] [blame] | 111 | // RRO's partition logic is different from the partition logic of other modules defined in soong/android/paths.go |
| 112 | // The default partition for RRO is "/product" and not "/system" |
| 113 | func rroPartition(ctx android.ModuleContext) string { |
| 114 | var partition string |
| 115 | if ctx.DeviceSpecific() { |
| 116 | partition = ctx.DeviceConfig().OdmPath() |
| 117 | } else if ctx.SocSpecific() { |
| 118 | partition = ctx.DeviceConfig().VendorPath() |
| 119 | } else if ctx.SystemExtSpecific() { |
| 120 | partition = ctx.DeviceConfig().SystemExtPath() |
| 121 | } else { |
| 122 | partition = ctx.DeviceConfig().ProductPath() |
| 123 | } |
| 124 | return partition |
| 125 | } |
| 126 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 127 | func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 128 | sdkDep := decodeSdkDep(ctx, android.SdkContext(r)) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 129 | if sdkDep.hasFrameworkLibs() { |
| 130 | r.aapt.deps(ctx, sdkDep) |
| 131 | } |
| 132 | |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 133 | cert := android.SrcIsModule(r.properties.Certificate.GetOrDefault(ctx, "")) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 134 | if cert != "" { |
| 135 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 136 | } |
| 137 | |
Cole Faust | b749347 | 2024-08-28 11:55:52 -0700 | [diff] [blame] | 138 | ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs.GetOrDefault(ctx, nil)...) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 139 | ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...) |
Jihoon Kang | 9f442dc | 2024-03-20 22:09:04 +0000 | [diff] [blame] | 140 | |
| 141 | for _, aconfig_declaration := range r.aaptProperties.Flags_packages { |
| 142 | ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) |
| 143 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 147 | // Compile and link resources |
| 148 | r.aapt.hasNoCode = true |
| 149 | // Do not remove resources without default values nor dedupe resource configurations with the same value |
| 150 | aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"} |
Artem Anashkin | 038866a | 2024-12-16 17:31:55 +0300 | [diff] [blame] | 151 | |
| 152 | // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided. |
| 153 | hasProduct := android.PrefixInList(r.aaptProperties.Aaptflags, "--product") |
| 154 | if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { |
| 155 | aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) |
| 156 | } |
| 157 | |
| 158 | if !Bool(r.aaptProperties.Aapt_include_all_resources) { |
| 159 | // Product AAPT config |
| 160 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
| 161 | aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig) |
| 162 | } |
| 163 | |
| 164 | // Product AAPT preferred config |
| 165 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
| 166 | aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
| 167 | } |
| 168 | } |
| 169 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 170 | // Allow the override of "package name" and "overlay target package name" |
| 171 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 172 | if overridden || r.overridableProperties.Package_name != nil { |
| 173 | // The product override variable has a priority over the package_name property. |
| 174 | if !overridden { |
| 175 | manifestPackageName = *r.overridableProperties.Package_name |
| 176 | } |
| 177 | aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName, false)...) |
| 178 | } |
| 179 | if r.overridableProperties.Target_package_name != nil { |
| 180 | aaptLinkFlags = append(aaptLinkFlags, |
| 181 | "--rename-overlay-target-package "+*r.overridableProperties.Target_package_name) |
| 182 | } |
Jeremy Meyer | 7e67129 | 2022-10-07 18:21:34 +0000 | [diff] [blame] | 183 | if r.overridableProperties.Category != nil { |
| 184 | aaptLinkFlags = append(aaptLinkFlags, |
| 185 | "--rename-overlay-category "+*r.overridableProperties.Category) |
| 186 | } |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 187 | aconfigTextFilePaths := getAconfigFilePaths(ctx) |
Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 188 | r.aapt.buildActions(ctx, |
| 189 | aaptBuildActionOptions{ |
| 190 | sdkContext: r, |
| 191 | enforceDefaultTargetSdkVersion: false, |
| 192 | extraLinkFlags: aaptLinkFlags, |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 193 | aconfigTextFiles: aconfigTextFilePaths, |
Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 194 | }, |
| 195 | ) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 196 | |
| 197 | // Sign the built package |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 198 | _, _, certificates := collectAppDeps(ctx, r, false, false) |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 199 | r.certificate, certificates = processMainCert(r.ModuleBase, r.properties.Certificate.GetOrDefault(ctx, ""), certificates, ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 200 | signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk") |
| 201 | var lineageFile android.Path |
| 202 | if lineage := String(r.properties.Lineage); lineage != "" { |
| 203 | lineageFile = android.PathForModuleSrc(ctx, lineage) |
| 204 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 205 | |
| 206 | rotationMinSdkVersion := String(r.properties.RotationMinSdkVersion) |
| 207 | |
| 208 | SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil, lineageFile, rotationMinSdkVersion) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 209 | |
| 210 | r.outputFile = signed |
Spandan Das | 5d1b929 | 2021-06-03 19:36:41 +0000 | [diff] [blame] | 211 | partition := rroPartition(ctx) |
| 212 | r.installDir = android.PathForModuleInPartitionInstall(ctx, partition, "overlay", String(r.properties.Theme)) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 213 | ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile) |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 214 | |
| 215 | android.SetProvider(ctx, FlagsPackagesProvider, FlagsPackages{ |
| 216 | AconfigTextFiles: aconfigTextFilePaths, |
| 217 | }) |
Wei Li | 986fe74 | 2025-01-30 15:14:42 -0800 | [diff] [blame] | 218 | |
Yu Liu | 0a37d42 | 2025-02-13 02:05:00 +0000 | [diff] [blame] | 219 | android.SetProvider(ctx, RuntimeResourceOverlayInfoProvider, RuntimeResourceOverlayInfo{ |
| 220 | OutputFile: r.OutputFile(), |
| 221 | Certificate: r.Certificate(), |
| 222 | Theme: r.Theme(), |
| 223 | }) |
| 224 | |
Wei Li | 986fe74 | 2025-01-30 15:14:42 -0800 | [diff] [blame] | 225 | buildComplianceMetadata(ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 228 | func (r *RuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 229 | return android.SdkSpecFrom(ctx, String(r.properties.Sdk_version)) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 232 | func (r *RuntimeResourceOverlay) SystemModules() string { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 233 | return "" |
| 234 | } |
| 235 | |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 236 | func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 237 | if r.properties.Min_sdk_version != nil { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 238 | return android.ApiLevelFrom(ctx, *r.properties.Min_sdk_version) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 239 | } |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 240 | return r.SdkVersion(ctx).ApiLevel |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 243 | func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { |
| 244 | return android.SdkSpecPrivate.ApiLevel |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 247 | func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 248 | return r.SdkVersion(ctx).ApiLevel |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | func (r *RuntimeResourceOverlay) Certificate() Certificate { |
| 252 | return r.certificate |
| 253 | } |
| 254 | |
| 255 | func (r *RuntimeResourceOverlay) OutputFile() android.Path { |
| 256 | return r.outputFile |
| 257 | } |
| 258 | |
| 259 | func (r *RuntimeResourceOverlay) Theme() string { |
| 260 | return String(r.properties.Theme) |
| 261 | } |
| 262 | |
| 263 | // runtime_resource_overlay generates a resource-only apk file that can overlay application and |
| 264 | // system resources at run time. |
| 265 | func RuntimeResourceOverlayFactory() android.Module { |
| 266 | module := &RuntimeResourceOverlay{} |
| 267 | module.AddProperties( |
| 268 | &module.properties, |
| 269 | &module.aaptProperties, |
| 270 | &module.overridableProperties) |
| 271 | |
| 272 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 273 | android.InitDefaultableModule(module) |
| 274 | android.InitOverridableModule(module, &module.properties.Overrides) |
| 275 | return module |
| 276 | } |
| 277 | |
| 278 | // runtime_resource_overlay properties that can be overridden by override_runtime_resource_overlay |
| 279 | type OverridableRuntimeResourceOverlayProperties struct { |
| 280 | // the package name of this app. The package name in the manifest file is used if one was not given. |
| 281 | Package_name *string |
| 282 | |
| 283 | // the target package name of this overlay app. The target package name in the manifest file is used if one was not given. |
| 284 | Target_package_name *string |
Jeremy Meyer | 7e67129 | 2022-10-07 18:21:34 +0000 | [diff] [blame] | 285 | |
| 286 | // the rro category of this overlay. The category in the manifest file is used if one was not given. |
| 287 | Category *string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | type OverrideRuntimeResourceOverlay struct { |
| 291 | android.ModuleBase |
| 292 | android.OverrideModuleBase |
| 293 | } |
| 294 | |
| 295 | func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(_ android.ModuleContext) { |
| 296 | // All the overrides happen in the base module. |
| 297 | // TODO(jungjw): Check the base module type. |
| 298 | } |
| 299 | |
| 300 | // override_runtime_resource_overlay is used to create a module based on another |
| 301 | // runtime_resource_overlay module by overriding some of its properties. |
| 302 | func OverrideRuntimeResourceOverlayModuleFactory() android.Module { |
| 303 | m := &OverrideRuntimeResourceOverlay{} |
| 304 | m.AddProperties(&OverridableRuntimeResourceOverlayProperties{}) |
| 305 | |
| 306 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 307 | android.InitOverrideModule(m) |
| 308 | return m |
| 309 | } |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 310 | |
| 311 | var ( |
| 312 | generateOverlayManifestFile = pctx.AndroidStaticRule("generate_overlay_manifest", |
| 313 | blueprint.RuleParams{ |
| 314 | Command: "build/make/tools/generate-enforce-rro-android-manifest.py " + |
| 315 | "--package-info $in " + |
| 316 | "--partition ${partition} " + |
| 317 | "--priority ${priority} -o $out", |
| 318 | CommandDeps: []string{"build/make/tools/generate-enforce-rro-android-manifest.py"}, |
| 319 | }, "partition", "priority", |
| 320 | ) |
| 321 | ) |
| 322 | |
| 323 | type AutogenRuntimeResourceOverlay struct { |
| 324 | android.ModuleBase |
| 325 | aapt |
| 326 | |
| 327 | properties AutogenRuntimeResourceOverlayProperties |
| 328 | |
Spandan Das | af8a3f5 | 2024-12-08 18:22:45 +0000 | [diff] [blame] | 329 | certificate Certificate |
| 330 | outputFile android.Path |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | type AutogenRuntimeResourceOverlayProperties struct { |
| 334 | Base *string |
| 335 | Sdk_version *string |
| 336 | Manifest *string `android:"path"` |
| 337 | } |
| 338 | |
| 339 | func AutogenRuntimeResourceOverlayFactory() android.Module { |
| 340 | m := &AutogenRuntimeResourceOverlay{} |
| 341 | m.AddProperties(&m.properties) |
| 342 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 343 | |
| 344 | return m |
| 345 | } |
| 346 | |
| 347 | type rroDependencyTag struct { |
| 348 | blueprint.DependencyTag |
| 349 | } |
| 350 | |
| 351 | // Autogenerated RROs should always depend on the source android_app that created it. |
| 352 | func (tag rroDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 353 | return false |
| 354 | } |
| 355 | |
| 356 | var rroDepTag = rroDependencyTag{} |
| 357 | |
| 358 | func (a *AutogenRuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 359 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
| 360 | if sdkDep.hasFrameworkLibs() { |
| 361 | a.aapt.deps(ctx, sdkDep) |
| 362 | } |
| 363 | ctx.AddDependency(ctx.Module(), rroDepTag, proptools.String(a.properties.Base)) |
| 364 | } |
| 365 | |
| 366 | func (a *AutogenRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 367 | if !a.Enabled(ctx) { |
| 368 | return |
| 369 | } |
| 370 | var rroDirs android.Paths |
| 371 | // Get rro dirs of the base app |
| 372 | ctx.VisitDirectDepsWithTag(rroDepTag, func(m android.Module) { |
| 373 | aarDep, _ := m.(AndroidLibraryDependency) |
| 374 | if ctx.InstallInProduct() { |
| 375 | rroDirs = filterRRO(aarDep.RRODirsDepSet(), product) |
| 376 | } else { |
| 377 | rroDirs = filterRRO(aarDep.RRODirsDepSet(), device) |
| 378 | } |
| 379 | }) |
| 380 | |
| 381 | if len(rroDirs) == 0 { |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | // Generate a manifest file |
| 386 | genManifest := android.PathForModuleGen(ctx, "AndroidManifest.xml") |
| 387 | partition := "vendor" |
| 388 | priority := "0" |
| 389 | if ctx.InstallInProduct() { |
| 390 | partition = "product" |
| 391 | priority = "1" |
| 392 | } |
| 393 | ctx.Build(pctx, android.BuildParams{ |
| 394 | Rule: generateOverlayManifestFile, |
| 395 | Input: android.PathForModuleSrc(ctx, proptools.String(a.properties.Manifest)), |
| 396 | Output: genManifest, |
| 397 | Args: map[string]string{ |
| 398 | "partition": partition, |
| 399 | "priority": priority, |
| 400 | }, |
| 401 | }) |
| 402 | |
| 403 | // Compile and link resources into package-res.apk |
| 404 | a.aapt.hasNoCode = true |
| 405 | aaptLinkFlags := []string{"--auto-add-overlay", "--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"} |
| 406 | |
| 407 | a.aapt.buildActions(ctx, |
| 408 | aaptBuildActionOptions{ |
Spandan Das | 1319389 | 2025-03-03 21:49:06 +0000 | [diff] [blame] | 409 | sdkContext: a, |
| 410 | extraLinkFlags: aaptLinkFlags, |
| 411 | rroDirs: &rroDirs, |
| 412 | manifestForAapt: genManifest, |
| 413 | aconfigTextFiles: getAconfigFilePaths(ctx), |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 414 | }, |
| 415 | ) |
| 416 | |
| 417 | if a.exportPackage == nil { |
| 418 | return |
| 419 | } |
| 420 | // Sign the built package |
Spandan Das | af8a3f5 | 2024-12-08 18:22:45 +0000 | [diff] [blame] | 421 | var certificates []Certificate |
| 422 | a.certificate, certificates = processMainCert(a.ModuleBase, "", nil, ctx) |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 423 | signed := android.PathForModuleOut(ctx, "signed", a.Name()+".apk") |
| 424 | SignAppPackage(ctx, signed, a.exportPackage, certificates, nil, nil, "") |
| 425 | a.outputFile = signed |
| 426 | |
| 427 | // Install the signed apk |
| 428 | installDir := android.PathForModuleInstall(ctx, "overlay") |
| 429 | ctx.InstallFile(installDir, signed.Base(), signed) |
Spandan Das | 1d1a0b8 | 2025-03-06 00:47:09 +0000 | [diff] [blame^] | 430 | |
| 431 | android.SetProvider(ctx, RuntimeResourceOverlayInfoProvider, RuntimeResourceOverlayInfo{ |
| 432 | OutputFile: signed, |
| 433 | Certificate: a.certificate, |
| 434 | }) |
Spandan Das | e2f98da | 2024-11-18 19:22:39 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | func (a *AutogenRuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 438 | return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version)) |
| 439 | } |
| 440 | |
| 441 | func (a *AutogenRuntimeResourceOverlay) SystemModules() string { |
| 442 | return "" |
| 443 | } |
| 444 | |
| 445 | func (a *AutogenRuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 446 | return a.SdkVersion(ctx).ApiLevel |
| 447 | } |
| 448 | |
| 449 | func (r *AutogenRuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { |
| 450 | return android.SdkSpecPrivate.ApiLevel |
| 451 | } |
| 452 | |
| 453 | func (a *AutogenRuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 454 | return a.SdkVersion(ctx).ApiLevel |
| 455 | } |
| 456 | |
| 457 | func (a *AutogenRuntimeResourceOverlay) InstallInProduct() bool { |
| 458 | return a.ProductSpecific() |
| 459 | } |