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 android_app_import and android_test_import. |
| 18 | |
| 19 | import ( |
| 20 | "reflect" |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 21 | "strings" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 22 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
| 24 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 25 | "github.com/google/blueprint/proptools" |
| 26 | |
| 27 | "android/soong/android" |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 28 | "android/soong/provenance" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | RegisterAppImportBuildComponents(android.InitRegistrationContext) |
| 33 | |
| 34 | initAndroidAppImportVariantGroupTypes() |
| 35 | } |
| 36 | |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 37 | var ( |
| 38 | uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{ |
| 39 | Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + |
| 40 | `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` + |
| 41 | `; else cp -f $in $out; fi`, |
| 42 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 43 | Description: "Uncompress embedded JNI libs", |
| 44 | }) |
| 45 | |
| 46 | uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{ |
| 47 | Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + |
| 48 | `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` + |
| 49 | `; else cp -f $in $out; fi`, |
| 50 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 51 | Description: "Uncompress dex files", |
| 52 | }) |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 53 | |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 54 | checkPresignedApkRule = pctx.AndroidStaticRule("check-presigned-apk", blueprint.RuleParams{ |
| 55 | Command: "build/soong/scripts/check_prebuilt_presigned_apk.py --aapt2 ${config.Aapt2Cmd} --zipalign ${config.ZipAlign} $extraArgs $in $out", |
| 56 | CommandDeps: []string{"build/soong/scripts/check_prebuilt_presigned_apk.py", "${config.Aapt2Cmd}", "${config.ZipAlign}"}, |
| 57 | Description: "Check presigned apk", |
| 58 | }, "extraArgs") |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 59 | ) |
| 60 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 61 | func RegisterAppImportBuildComponents(ctx android.RegistrationContext) { |
| 62 | ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) |
| 63 | ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 64 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 65 | ctx.BottomUp("disable_prebuilts_without_apk", disablePrebuiltsWithoutApkMutator) |
| 66 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | type AndroidAppImport struct { |
| 70 | android.ModuleBase |
| 71 | android.DefaultableModuleBase |
| 72 | android.ApexModuleBase |
| 73 | prebuilt android.Prebuilt |
| 74 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 75 | properties AndroidAppImportProperties |
| 76 | dpiVariants interface{} |
| 77 | archVariants interface{} |
| 78 | arch_dpiVariants interface{} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 79 | |
| 80 | outputFile android.Path |
| 81 | certificate Certificate |
| 82 | |
| 83 | dexpreopter |
| 84 | |
| 85 | usesLibrary usesLibrary |
| 86 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 87 | installPath android.InstallPath |
| 88 | |
| 89 | hideApexVariantFromMake bool |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 90 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 91 | provenanceMetaDataFile android.Path |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | type AndroidAppImportProperties struct { |
| 95 | // A prebuilt apk to import |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 96 | Apk proptools.Configurable[string] `android:"path,replace_instead_of_append"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 97 | |
| 98 | // The name of a certificate in the default certificate directory or an android_app_certificate |
| 99 | // module name in the form ":module". Should be empty if presigned or default_dev_cert is set. |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame^] | 100 | Certificate proptools.Configurable[string] `android:"replace_instead_of_append"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 101 | |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 102 | // Names of extra android_app_certificate modules to sign the apk with in the form ":module". |
| 103 | Additional_certificates []string |
| 104 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 105 | // Set this flag to true if the prebuilt apk is already signed. The certificate property must not |
| 106 | // be set for presigned modules. |
| 107 | Presigned *bool |
| 108 | |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 109 | // Name of the signing certificate lineage file or filegroup module. |
| 110 | Lineage *string `android:"path"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 111 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 112 | // For overriding the --rotation-min-sdk-version property of apksig |
| 113 | RotationMinSdkVersion *string |
| 114 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 115 | // Sign with the default system dev certificate. Must be used judiciously. Most imported apps |
| 116 | // need to either specify a specific certificate or be presigned. |
| 117 | Default_dev_cert *bool |
| 118 | |
| 119 | // Specifies that this app should be installed to the priv-app directory, |
| 120 | // where the system will grant it additional privileges not available to |
| 121 | // normal apps. |
| 122 | Privileged *bool |
| 123 | |
| 124 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 125 | // (in Make or Soong). |
| 126 | // This does not completely prevent installation of the overridden binaries, but if both |
| 127 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 128 | // from PRODUCT_PACKAGES. |
| 129 | Overrides []string |
| 130 | |
| 131 | // Optional name for the installed app. If unspecified, it is derived from the module name. |
| 132 | Filename *string |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 133 | |
| 134 | // If set, create package-export.apk, which other packages can |
| 135 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
| 136 | Export_package_resources *bool |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 137 | |
| 138 | // Optional. Install to a subdirectory of the default install path for the module |
| 139 | Relative_install_path *string |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 140 | |
| 141 | // Whether the prebuilt apk can be installed without additional processing. Default is false. |
| 142 | Preprocessed *bool |
| 143 | |
| 144 | // Whether or not to skip checking the preprocessed apk for proper alignment and uncompressed |
| 145 | // JNI libs and dex files. Default is false |
| 146 | Skip_preprocessed_apk_checks *bool |
Spandan Das | efa1465 | 2024-02-27 18:19:16 +0000 | [diff] [blame] | 147 | |
| 148 | // Name of the source soong module that gets shadowed by this prebuilt |
| 149 | // If unspecified, follows the naming convention that the source module of |
| 150 | // the prebuilt is Name() without "prebuilt_" prefix |
| 151 | Source_module_name *string |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 152 | |
| 153 | // Path to the .prebuilt_info file of the prebuilt app. |
| 154 | // In case of mainline modules, the .prebuilt_info file contains the build_id that was used |
| 155 | // to generate the prebuilt. |
| 156 | Prebuilt_info *string `android:"path"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | func (a *AndroidAppImport) IsInstallable() bool { |
| 160 | return true |
| 161 | } |
| 162 | |
| 163 | // Updates properties with variant-specific values. |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 164 | // This happens as a DefaultableHook instead of a LoadHook because we want to run it after |
| 165 | // soong config variables are applied. |
| 166 | func (a *AndroidAppImport) processVariants(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 167 | config := ctx.Config() |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 168 | dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName(DpiGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 169 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 170 | // Try DPI variant matches in the reverse-priority order so that the highest priority match |
| 171 | // overwrites everything else. |
| 172 | // TODO(jungjw): Can we optimize this by making it priority order? |
| 173 | for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- { |
| 174 | MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i]) |
| 175 | } |
| 176 | if config.ProductAAPTPreferredConfig() != "" { |
| 177 | MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig()) |
| 178 | } |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 179 | archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName(ArchGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 180 | archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType |
| 181 | MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name) |
| 182 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 183 | // Process "arch" includes "dpi_variants" |
| 184 | archStructPtr := reflect.ValueOf(a.arch_dpiVariants).Elem().FieldByName(ArchGroupName) |
| 185 | if archStruct := archStructPtr.Elem(); archStruct.IsValid() { |
| 186 | archPartPropsPtr := archStruct.FieldByName(proptools.FieldNameForProperty(archType.Name)) |
| 187 | if archPartProps := archPartPropsPtr.Elem(); archPartProps.IsValid() { |
| 188 | archDpiPropsPtr := archPartProps.FieldByName(DpiGroupName) |
| 189 | if archDpiProps := archDpiPropsPtr.Elem(); archDpiProps.IsValid() { |
| 190 | for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- { |
| 191 | MergePropertiesFromVariant(ctx, &a.properties, archDpiProps, config.ProductAAPTPrebuiltDPI()[i]) |
| 192 | } |
| 193 | if config.ProductAAPTPreferredConfig() != "" { |
| 194 | MergePropertiesFromVariant(ctx, &a.properties, archDpiProps, config.ProductAAPTPreferredConfig()) |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | func MergePropertiesFromVariant(ctx android.EarlyModuleContext, |
| 202 | dst interface{}, variantGroup reflect.Value, variant string) { |
| 203 | src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant)) |
| 204 | if !src.IsValid() { |
| 205 | return |
| 206 | } |
| 207 | |
| 208 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend) |
| 209 | if err != nil { |
| 210 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 211 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 212 | } else { |
| 213 | panic(err) |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 218 | // disablePrebuiltsWithoutApkMutator is a pre-arch mutator that disables AndroidAppImport or |
| 219 | // AndroidTestImport modules that don't have an apk set. We need this separate mutator instead |
| 220 | // of doing it in processVariants because processVariants is a defaultable hook, and configurable |
| 221 | // properties can only be evaluated after the defaults (and eventually, base configurabtion) |
| 222 | // mutators. |
| 223 | func disablePrebuiltsWithoutApkMutator(ctx android.BottomUpMutatorContext) { |
| 224 | switch a := ctx.Module().(type) { |
| 225 | case *AndroidAppImport: |
| 226 | if a.properties.Apk.GetOrDefault(ctx, "") == "" { |
| 227 | // Disable this module since the apk property is still empty after processing all |
| 228 | // matching variants. This likely means there is no matching variant, and the default |
| 229 | // variant doesn't have an apk property value either. |
| 230 | a.Disable() |
| 231 | } |
| 232 | case *AndroidTestImport: |
| 233 | if a.properties.Apk.GetOrDefault(ctx, "") == "" { |
| 234 | // Disable this module since the apk property is still empty after processing all |
| 235 | // matching variants. This likely means there is no matching variant, and the default |
| 236 | // variant doesn't have an apk property value either. |
| 237 | a.Disable() |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 242 | func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame^] | 243 | cert := android.SrcIsModule(a.properties.Certificate.GetOrDefault(ctx, "")) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 244 | if cert != "" { |
| 245 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 246 | } |
| 247 | |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 248 | for _, cert := range a.properties.Additional_certificates { |
| 249 | cert = android.SrcIsModule(cert) |
| 250 | if cert != "" { |
| 251 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 252 | } else { |
| 253 | ctx.PropertyErrorf("additional_certificates", |
| 254 | `must be names of android_app_certificate modules in the form ":module"`) |
| 255 | } |
| 256 | } |
| 257 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 258 | a.usesLibrary.deps(ctx, true) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | func (a *AndroidAppImport) uncompressEmbeddedJniLibs( |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 262 | ctx android.ModuleContext, inputPath android.Path, outputPath android.WritablePath) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 263 | // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing |
| 264 | // with them may invalidate pre-existing signature data. |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 265 | if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || Bool(a.properties.Preprocessed)) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 266 | ctx.Build(pctx, android.BuildParams{ |
| 267 | Rule: android.Cp, |
| 268 | Output: outputPath, |
| 269 | Input: inputPath, |
| 270 | }) |
| 271 | return |
| 272 | } |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 273 | |
| 274 | ctx.Build(pctx, android.BuildParams{ |
| 275 | Rule: uncompressEmbeddedJniLibsRule, |
| 276 | Input: inputPath, |
| 277 | Output: outputPath, |
| 278 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // Returns whether this module should have the dex file stored uncompressed in the APK. |
| 282 | func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 283 | if ctx.Config().UnbundledBuild() || proptools.Bool(a.properties.Preprocessed) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 284 | return false |
| 285 | } |
| 286 | |
Ulya Trafimovich | 0061c0d | 2021-09-01 15:40:38 +0100 | [diff] [blame] | 287 | // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false. |
| 288 | if a.Privileged() { |
| 289 | return ctx.Config().UncompressPrivAppDex() |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 292 | return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 295 | func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 296 | a.generateAndroidBuildActions(ctx) |
| 297 | } |
| 298 | |
| 299 | func (a *AndroidAppImport) InstallApkName() string { |
| 300 | return a.BaseModuleName() |
| 301 | } |
| 302 | |
Spandan Das | efa1465 | 2024-02-27 18:19:16 +0000 | [diff] [blame] | 303 | func (a *AndroidAppImport) BaseModuleName() string { |
| 304 | return proptools.StringDefault(a.properties.Source_module_name, a.ModuleBase.Name()) |
| 305 | } |
| 306 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 307 | func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 308 | if a.Name() == "prebuilt_framework-res" { |
| 309 | ctx.ModuleErrorf("prebuilt_framework-res found. This used to have special handling in soong, but was removed due to prebuilt_framework-res no longer existing. This check is to ensure it doesn't come back without readding the special handling.") |
| 310 | } |
| 311 | |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 312 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 313 | if !apexInfo.IsForPlatform() { |
| 314 | a.hideApexVariantFromMake = true |
| 315 | } |
| 316 | |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 317 | if Bool(a.properties.Preprocessed) { |
| 318 | if a.properties.Presigned != nil && !*a.properties.Presigned { |
| 319 | ctx.ModuleErrorf("Setting preprocessed: true implies presigned: true, so you cannot set presigned to false") |
| 320 | } |
| 321 | t := true |
| 322 | a.properties.Presigned = &t |
| 323 | } |
| 324 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 325 | numCertPropsSet := 0 |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame^] | 326 | if a.properties.Certificate.GetOrDefault(ctx, "") != "" { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 327 | numCertPropsSet++ |
| 328 | } |
| 329 | if Bool(a.properties.Presigned) { |
| 330 | numCertPropsSet++ |
| 331 | } |
| 332 | if Bool(a.properties.Default_dev_cert) { |
| 333 | numCertPropsSet++ |
| 334 | } |
| 335 | if numCertPropsSet != 1 { |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 336 | ctx.ModuleErrorf("One and only one of certficate, presigned (implied by preprocessed), and default_dev_cert properties must be set") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 339 | // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK |
| 340 | // TODO: LOCAL_PACKAGE_SPLITS |
| 341 | |
| 342 | srcApk := a.prebuilt.SingleSourcePath(ctx) |
| 343 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 344 | // TODO: Install or embed JNI libraries |
| 345 | |
| 346 | // Uncompress JNI libraries in the apk |
| 347 | jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk") |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 348 | a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 349 | |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 350 | var pathFragments []string |
| 351 | relInstallPath := String(a.properties.Relative_install_path) |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 352 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 353 | if Bool(a.properties.Privileged) { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 354 | pathFragments = []string{"priv-app", relInstallPath, a.BaseModuleName()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 355 | } else if ctx.InstallInTestcases() { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 356 | pathFragments = []string{relInstallPath, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 357 | } else { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 358 | pathFragments = []string{"app", relInstallPath, a.BaseModuleName()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 361 | installDir := android.PathForModuleInstall(ctx, pathFragments...) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 362 | a.dexpreopter.isApp = true |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 363 | a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk") |
| 364 | a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned) |
| 365 | a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) |
| 366 | |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 367 | a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries(ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 368 | a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 369 | if a.usesLibrary.shouldDisableDexpreopt { |
| 370 | a.dexpreopter.disableDexpreopt() |
| 371 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 372 | |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 373 | if a.usesLibrary.enforceUsesLibraries(ctx) { |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 374 | a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk, &a.dexpreopter.classLoaderContexts) |
Ulya Trafimovich | fe927a2 | 2021-02-26 14:36:48 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 377 | a.dexpreopter.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), jnisUncompressed) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 378 | if a.dexpreopter.uncompressedDex { |
| 379 | dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 380 | ctx.Build(pctx, android.BuildParams{ |
| 381 | Rule: uncompressDexRule, |
| 382 | Input: jnisUncompressed, |
| 383 | Output: dexUncompressed, |
| 384 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 385 | jnisUncompressed = dexUncompressed |
| 386 | } |
| 387 | |
| 388 | apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk") |
| 389 | |
| 390 | // TODO: Handle EXTERNAL |
| 391 | |
| 392 | // Sign or align the package if package has not been preprocessed |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 393 | |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 394 | if proptools.Bool(a.properties.Preprocessed) { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 395 | validationStamp := a.validatePresignedApk(ctx, srcApk) |
| 396 | output := android.PathForModuleOut(ctx, apkFilename) |
| 397 | ctx.Build(pctx, android.BuildParams{ |
| 398 | Rule: android.Cp, |
| 399 | Input: srcApk, |
| 400 | Output: output, |
| 401 | Validation: validationStamp, |
| 402 | }) |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 403 | a.outputFile = output |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 404 | a.certificate = PresignedCertificate |
| 405 | } else if !Bool(a.properties.Presigned) { |
| 406 | // If the certificate property is empty at this point, default_dev_cert must be set to true. |
| 407 | // Which makes processMainCert's behavior for the empty cert string WAI. |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 408 | _, _, certificates := collectAppDeps(ctx, a, false, false) |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame^] | 409 | a.certificate, certificates = processMainCert(a.ModuleBase, a.properties.Certificate.GetOrDefault(ctx, ""), certificates, ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 410 | signed := android.PathForModuleOut(ctx, "signed", apkFilename) |
| 411 | var lineageFile android.Path |
| 412 | if lineage := String(a.properties.Lineage); lineage != "" { |
| 413 | lineageFile = android.PathForModuleSrc(ctx, lineage) |
| 414 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 415 | |
| 416 | rotationMinSdkVersion := String(a.properties.RotationMinSdkVersion) |
| 417 | |
| 418 | SignAppPackage(ctx, signed, jnisUncompressed, certificates, nil, lineageFile, rotationMinSdkVersion) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 419 | a.outputFile = signed |
| 420 | } else { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 421 | validationStamp := a.validatePresignedApk(ctx, srcApk) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 422 | alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename) |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 423 | TransformZipAlign(ctx, alignedApk, jnisUncompressed, []android.Path{validationStamp}) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 424 | a.outputFile = alignedApk |
| 425 | a.certificate = PresignedCertificate |
| 426 | } |
| 427 | |
| 428 | // TODO: Optionally compress the output apk. |
| 429 | |
| 430 | if apexInfo.IsForPlatform() { |
| 431 | a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 432 | artifactPath := android.PathForModuleSrc(ctx, a.properties.Apk.GetOrDefault(ctx, "")) |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 433 | a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 436 | providePrebuiltInfo(ctx, |
| 437 | prebuiltInfoProps{ |
| 438 | baseModuleName: a.BaseModuleName(), |
| 439 | isPrebuilt: true, |
| 440 | prebuiltInfo: a.properties.Prebuilt_info, |
| 441 | }, |
| 442 | ) |
| 443 | |
mrziwang | 68786d8 | 2024-07-09 10:41:55 -0700 | [diff] [blame] | 444 | ctx.SetOutputFiles([]android.Path{a.outputFile}, "") |
| 445 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 446 | // TODO: androidmk converter jni libs |
| 447 | } |
| 448 | |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 449 | func (a *AndroidAppImport) validatePresignedApk(ctx android.ModuleContext, srcApk android.Path) android.Path { |
| 450 | stamp := android.PathForModuleOut(ctx, "validated-prebuilt", "check.stamp") |
| 451 | var extraArgs []string |
Cole Faust | 93b89b4 | 2023-07-20 17:31:16 -0700 | [diff] [blame] | 452 | if a.Privileged() { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 453 | extraArgs = append(extraArgs, "--privileged") |
Rashid Zaman | 3bd2870 | 2024-07-23 17:23:05 -0700 | [diff] [blame] | 454 | if ctx.Config().UncompressPrivAppDex() { |
| 455 | extraArgs = append(extraArgs, "--uncompress-priv-app-dex") |
| 456 | } |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 457 | } |
| 458 | if proptools.Bool(a.properties.Skip_preprocessed_apk_checks) { |
| 459 | extraArgs = append(extraArgs, "--skip-preprocessed-apk-checks") |
| 460 | } |
| 461 | if proptools.Bool(a.properties.Preprocessed) { |
| 462 | extraArgs = append(extraArgs, "--preprocessed") |
Cole Faust | 93b89b4 | 2023-07-20 17:31:16 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 465 | ctx.Build(pctx, android.BuildParams{ |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 466 | Rule: checkPresignedApkRule, |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 467 | Input: srcApk, |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 468 | Output: stamp, |
| 469 | Args: map[string]string{ |
| 470 | "extraArgs": strings.Join(extraArgs, " "), |
| 471 | }, |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 472 | }) |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 473 | return stamp |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 476 | func (a *AndroidAppImport) Prebuilt() *android.Prebuilt { |
| 477 | return &a.prebuilt |
| 478 | } |
| 479 | |
| 480 | func (a *AndroidAppImport) Name() string { |
| 481 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 482 | } |
| 483 | |
| 484 | func (a *AndroidAppImport) OutputFile() android.Path { |
| 485 | return a.outputFile |
| 486 | } |
| 487 | |
| 488 | func (a *AndroidAppImport) JacocoReportClassesFile() android.Path { |
| 489 | return nil |
| 490 | } |
| 491 | |
| 492 | func (a *AndroidAppImport) Certificate() Certificate { |
| 493 | return a.certificate |
| 494 | } |
| 495 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 496 | func (a *AndroidAppImport) ProvenanceMetaDataFile() android.Path { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 497 | return a.provenanceMetaDataFile |
| 498 | } |
| 499 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 500 | func (a *AndroidAppImport) PrivAppAllowlist() android.OptionalPath { |
| 501 | return android.OptionalPath{} |
| 502 | } |
| 503 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 504 | const ( |
| 505 | ArchGroupName = "Arch" |
| 506 | DpiGroupName = "Dpi_variants" |
| 507 | ) |
| 508 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 509 | var dpiVariantGroupType reflect.Type |
| 510 | var archVariantGroupType reflect.Type |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 511 | var archdpiVariantGroupType reflect.Type |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 512 | var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"} |
| 513 | |
| 514 | func initAndroidAppImportVariantGroupTypes() { |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 515 | dpiVariantGroupType = createVariantGroupType(supportedDpis, DpiGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 516 | |
| 517 | archNames := make([]string, len(android.ArchTypeList())) |
| 518 | for i, archType := range android.ArchTypeList() { |
| 519 | archNames[i] = archType.Name |
| 520 | } |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 521 | archVariantGroupType = createVariantGroupType(archNames, ArchGroupName) |
| 522 | archdpiVariantGroupType = createArchDpiVariantGroupType(archNames, supportedDpis) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // Populates all variant struct properties at creation time. |
| 526 | func (a *AndroidAppImport) populateAllVariantStructs() { |
| 527 | a.dpiVariants = reflect.New(dpiVariantGroupType).Interface() |
| 528 | a.AddProperties(a.dpiVariants) |
| 529 | |
| 530 | a.archVariants = reflect.New(archVariantGroupType).Interface() |
| 531 | a.AddProperties(a.archVariants) |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 532 | |
| 533 | a.arch_dpiVariants = reflect.New(archdpiVariantGroupType).Interface() |
| 534 | a.AddProperties(a.arch_dpiVariants) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | func (a *AndroidAppImport) Privileged() bool { |
| 538 | return Bool(a.properties.Privileged) |
| 539 | } |
| 540 | |
| 541 | func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool { |
| 542 | // android_app_import might have extra dependencies via uses_libs property. |
| 543 | // Don't track the dependency as we don't automatically add those libraries |
| 544 | // to the classpath. It should be explicitly added to java_libs property of APEX |
| 545 | return false |
| 546 | } |
| 547 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 548 | func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 549 | return android.SdkSpecPrivate |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 552 | func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 553 | return android.SdkSpecPrivate.ApiLevel |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | var _ android.ApexModule = (*AndroidAppImport)(nil) |
| 557 | |
| 558 | // Implements android.ApexModule |
| 559 | func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 560 | sdkVersion android.ApiLevel) error { |
| 561 | // Do not check for prebuilts against the min_sdk_version of enclosing APEX |
| 562 | return nil |
| 563 | } |
| 564 | |
| 565 | func createVariantGroupType(variants []string, variantGroupName string) reflect.Type { |
| 566 | props := reflect.TypeOf((*AndroidAppImportProperties)(nil)) |
| 567 | |
| 568 | variantFields := make([]reflect.StructField, len(variants)) |
| 569 | for i, variant := range variants { |
| 570 | variantFields[i] = reflect.StructField{ |
| 571 | Name: proptools.FieldNameForProperty(variant), |
| 572 | Type: props, |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | variantGroupStruct := reflect.StructOf(variantFields) |
| 577 | return reflect.StructOf([]reflect.StructField{ |
| 578 | { |
| 579 | Name: variantGroupName, |
| 580 | Type: variantGroupStruct, |
| 581 | }, |
| 582 | }) |
| 583 | } |
| 584 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 585 | func createArchDpiVariantGroupType(archNames []string, dpiNames []string) reflect.Type { |
| 586 | props := reflect.TypeOf((*AndroidAppImportProperties)(nil)) |
| 587 | |
| 588 | dpiVariantFields := make([]reflect.StructField, len(dpiNames)) |
| 589 | for i, variant_dpi := range dpiNames { |
| 590 | dpiVariantFields[i] = reflect.StructField{ |
| 591 | Name: proptools.FieldNameForProperty(variant_dpi), |
| 592 | Type: props, |
| 593 | } |
| 594 | } |
| 595 | dpiVariantGroupStruct := reflect.StructOf(dpiVariantFields) |
| 596 | dpi_struct := reflect.StructOf([]reflect.StructField{ |
| 597 | { |
| 598 | Name: DpiGroupName, |
| 599 | Type: reflect.PointerTo(dpiVariantGroupStruct), |
| 600 | }, |
| 601 | }) |
| 602 | |
| 603 | archVariantFields := make([]reflect.StructField, len(archNames)) |
| 604 | for i, variant_arch := range archNames { |
| 605 | archVariantFields[i] = reflect.StructField{ |
| 606 | Name: proptools.FieldNameForProperty(variant_arch), |
| 607 | Type: reflect.PointerTo(dpi_struct), |
| 608 | } |
| 609 | } |
| 610 | archVariantGroupStruct := reflect.StructOf(archVariantFields) |
| 611 | |
| 612 | return_struct := reflect.StructOf([]reflect.StructField{ |
| 613 | { |
| 614 | Name: ArchGroupName, |
| 615 | Type: reflect.PointerTo(archVariantGroupStruct), |
| 616 | }, |
| 617 | }) |
| 618 | return return_struct |
| 619 | } |
| 620 | |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 621 | func (a *AndroidAppImport) UsesLibrary() *usesLibrary { |
| 622 | return &a.usesLibrary |
| 623 | } |
| 624 | |
| 625 | var _ ModuleWithUsesLibrary = (*AndroidAppImport)(nil) |
| 626 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 627 | // android_app_import imports a prebuilt apk with additional processing specified in the module. |
| 628 | // DPI-specific apk source files can be specified using dpi_variants. Example: |
| 629 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 630 | // android_app_import { |
| 631 | // name: "example_import", |
| 632 | // apk: "prebuilts/example.apk", |
| 633 | // dpi_variants: { |
| 634 | // mdpi: { |
| 635 | // apk: "prebuilts/example_mdpi.apk", |
| 636 | // }, |
| 637 | // xhdpi: { |
| 638 | // apk: "prebuilts/example_xhdpi.apk", |
| 639 | // }, |
| 640 | // }, |
| 641 | // presigned: true, |
| 642 | // } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 643 | func AndroidAppImportFactory() android.Module { |
| 644 | module := &AndroidAppImport{} |
| 645 | module.AddProperties(&module.properties) |
| 646 | module.AddProperties(&module.dexpreoptProperties) |
| 647 | module.AddProperties(&module.usesLibrary.usesLibraryProperties) |
| 648 | module.populateAllVariantStructs() |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 649 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 650 | module.processVariants(ctx) |
| 651 | }) |
| 652 | |
| 653 | android.InitApexModule(module) |
| 654 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 655 | android.InitDefaultableModule(module) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 656 | android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 657 | |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 658 | module.usesLibrary.enforce = true |
| 659 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 660 | return module |
| 661 | } |
| 662 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 663 | type AndroidTestImport struct { |
| 664 | AndroidAppImport |
| 665 | |
Jiyong Park | 2f83b31 | 2022-10-20 20:18:35 +0900 | [diff] [blame] | 666 | testProperties struct { |
| 667 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 668 | // installed into. |
| 669 | Test_suites []string `android:"arch_variant"` |
| 670 | |
| 671 | // list of files or filegroup modules that provide data that should be installed alongside |
| 672 | // the test |
| 673 | Data []string `android:"path"` |
| 674 | |
| 675 | // Install the test into a folder named for the module in all test suites. |
| 676 | Per_testcase_directory *bool |
| 677 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 678 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 679 | data android.Paths |
| 680 | } |
| 681 | |
| 682 | func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 683 | a.generateAndroidBuildActions(ctx) |
| 684 | |
| 685 | a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) |
| 686 | } |
| 687 | |
| 688 | func (a *AndroidTestImport) InstallInTestcases() bool { |
| 689 | return true |
| 690 | } |
| 691 | |
| 692 | // android_test_import imports a prebuilt test apk with additional processing specified in the |
| 693 | // module. DPI or arch variant configurations can be made as with android_app_import. |
| 694 | func AndroidTestImportFactory() android.Module { |
| 695 | module := &AndroidTestImport{} |
| 696 | module.AddProperties(&module.properties) |
| 697 | module.AddProperties(&module.dexpreoptProperties) |
| 698 | module.AddProperties(&module.testProperties) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 699 | module.populateAllVariantStructs() |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 700 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 701 | module.processVariants(ctx) |
| 702 | }) |
| 703 | |
| 704 | module.dexpreopter.isTest = true |
| 705 | |
| 706 | android.InitApexModule(module) |
| 707 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 708 | android.InitDefaultableModule(module) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 709 | android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 710 | |
| 711 | return module |
| 712 | } |