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