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