blob: e24e7804e62bfd2cc9731e3c025525b20c836a6b [file] [log] [blame]
Jaewoong Jungf9b44652020-12-21 12:29:12 -08001// 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
15package java
16
17// This file contains the module implementations for android_app_import and android_test_import.
18
19import (
Cole Faust4ec178c2023-01-13 12:03:38 -080020 "github.com/google/blueprint"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080021 "reflect"
22
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
Wei Li340ee8e2022-03-18 17:33:24 -070026 "android/soong/provenance"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080027)
28
29func init() {
30 RegisterAppImportBuildComponents(android.InitRegistrationContext)
31
32 initAndroidAppImportVariantGroupTypes()
33}
34
Cole Faust4ec178c2023-01-13 12:03:38 -080035var (
36 uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{
37 Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` +
38 `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` +
39 `; else cp -f $in $out; fi`,
40 CommandDeps: []string{"${config.Zip2ZipCmd}"},
41 Description: "Uncompress embedded JNI libs",
42 })
43
44 uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{
45 Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` +
46 `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` +
47 `; else cp -f $in $out; fi`,
48 CommandDeps: []string{"${config.Zip2ZipCmd}"},
49 Description: "Uncompress dex files",
50 })
51)
52
Jaewoong Jungf9b44652020-12-21 12:29:12 -080053func RegisterAppImportBuildComponents(ctx android.RegistrationContext) {
54 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
55 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
56}
57
58type AndroidAppImport struct {
59 android.ModuleBase
60 android.DefaultableModuleBase
61 android.ApexModuleBase
62 prebuilt android.Prebuilt
63
64 properties AndroidAppImportProperties
65 dpiVariants interface{}
66 archVariants interface{}
67
68 outputFile android.Path
69 certificate Certificate
70
71 dexpreopter
72
73 usesLibrary usesLibrary
74
75 preprocessed bool
76
77 installPath android.InstallPath
78
79 hideApexVariantFromMake bool
Wei Li340ee8e2022-03-18 17:33:24 -070080
81 provenanceMetaDataFile android.OutputPath
Jaewoong Jungf9b44652020-12-21 12:29:12 -080082}
83
84type AndroidAppImportProperties struct {
85 // A prebuilt apk to import
Jooyung Hanf05ca9c2021-06-28 21:48:51 +090086 Apk *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -080087
88 // The name of a certificate in the default certificate directory or an android_app_certificate
89 // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
90 Certificate *string
91
Jaewoong Jung25ae8de2021-03-08 17:37:46 -080092 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
93 Additional_certificates []string
94
Jaewoong Jungf9b44652020-12-21 12:29:12 -080095 // Set this flag to true if the prebuilt apk is already signed. The certificate property must not
96 // be set for presigned modules.
97 Presigned *bool
98
Jaewoong Jung1c1b6e62021-03-09 15:02:31 -080099 // Name of the signing certificate lineage file or filegroup module.
100 Lineage *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800101
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -0400102 // For overriding the --rotation-min-sdk-version property of apksig
103 RotationMinSdkVersion *string
104
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800105 // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
106 // need to either specify a specific certificate or be presigned.
107 Default_dev_cert *bool
108
109 // Specifies that this app should be installed to the priv-app directory,
110 // where the system will grant it additional privileges not available to
111 // normal apps.
112 Privileged *bool
113
114 // Names of modules to be overridden. Listed modules can only be other binaries
115 // (in Make or Soong).
116 // This does not completely prevent installation of the overridden binaries, but if both
117 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
118 // from PRODUCT_PACKAGES.
119 Overrides []string
120
121 // Optional name for the installed app. If unspecified, it is derived from the module name.
122 Filename *string
Bill Peckhama036da92021-01-08 16:09:09 -0800123
124 // If set, create package-export.apk, which other packages can
125 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
126 Export_package_resources *bool
Spandan Dasd1fac642021-05-18 17:01:41 +0000127
128 // Optional. Install to a subdirectory of the default install path for the module
129 Relative_install_path *string
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800130}
131
132func (a *AndroidAppImport) IsInstallable() bool {
133 return true
134}
135
136// Updates properties with variant-specific values.
137func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
138 config := ctx.Config()
139
140 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
141 // Try DPI variant matches in the reverse-priority order so that the highest priority match
142 // overwrites everything else.
143 // TODO(jungjw): Can we optimize this by making it priority order?
144 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
145 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
146 }
147 if config.ProductAAPTPreferredConfig() != "" {
148 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
149 }
150
151 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
152 archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType
153 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
154
155 if String(a.properties.Apk) == "" {
156 // Disable this module since the apk property is still empty after processing all matching
157 // variants. This likely means there is no matching variant, and the default variant doesn't
158 // have an apk property value either.
159 a.Disable()
160 }
161}
162
163func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
164 dst interface{}, variantGroup reflect.Value, variant string) {
165 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
166 if !src.IsValid() {
167 return
168 }
169
170 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
171 if err != nil {
172 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
173 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
174 } else {
175 panic(err)
176 }
177 }
178}
179
Bill Peckhama036da92021-01-08 16:09:09 -0800180func (a *AndroidAppImport) isPrebuiltFrameworkRes() bool {
181 return a.Name() == "prebuilt_framework-res"
182}
183
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800184func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
185 cert := android.SrcIsModule(String(a.properties.Certificate))
186 if cert != "" {
187 ctx.AddDependency(ctx.Module(), certificateTag, cert)
188 }
189
Jaewoong Jung25ae8de2021-03-08 17:37:46 -0800190 for _, cert := range a.properties.Additional_certificates {
191 cert = android.SrcIsModule(cert)
192 if cert != "" {
193 ctx.AddDependency(ctx.Module(), certificateTag, cert)
194 } else {
195 ctx.PropertyErrorf("additional_certificates",
196 `must be names of android_app_certificate modules in the form ":module"`)
197 }
198 }
199
Bill Peckhama036da92021-01-08 16:09:09 -0800200 a.usesLibrary.deps(ctx, !a.isPrebuiltFrameworkRes())
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800201}
202
203func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
204 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
205 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
206 // with them may invalidate pre-existing signature data.
207 if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || a.preprocessed) {
208 ctx.Build(pctx, android.BuildParams{
209 Rule: android.Cp,
210 Output: outputPath,
211 Input: inputPath,
212 })
213 return
214 }
Cole Faust4ec178c2023-01-13 12:03:38 -0800215
216 ctx.Build(pctx, android.BuildParams{
217 Rule: uncompressEmbeddedJniLibsRule,
218 Input: inputPath,
219 Output: outputPath,
220 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800221}
222
223// Returns whether this module should have the dex file stored uncompressed in the APK.
224func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
225 if ctx.Config().UnbundledBuild() || a.preprocessed {
226 return false
227 }
228
Ulya Trafimovich0061c0d2021-09-01 15:40:38 +0100229 // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false.
230 if a.Privileged() {
231 return ctx.Config().UncompressPrivAppDex()
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800232 }
233
234 return shouldUncompressDex(ctx, &a.dexpreopter)
235}
236
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800237func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
238 a.generateAndroidBuildActions(ctx)
239}
240
241func (a *AndroidAppImport) InstallApkName() string {
242 return a.BaseModuleName()
243}
244
245func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
246 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
247 if !apexInfo.IsForPlatform() {
248 a.hideApexVariantFromMake = true
249 }
250
251 numCertPropsSet := 0
252 if String(a.properties.Certificate) != "" {
253 numCertPropsSet++
254 }
255 if Bool(a.properties.Presigned) {
256 numCertPropsSet++
257 }
258 if Bool(a.properties.Default_dev_cert) {
259 numCertPropsSet++
260 }
261 if numCertPropsSet != 1 {
262 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
263 }
264
Sam Delmerico82602492022-06-10 17:05:42 +0000265 _, _, certificates := collectAppDeps(ctx, a, false, false)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800266
267 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
268 // TODO: LOCAL_PACKAGE_SPLITS
269
270 srcApk := a.prebuilt.SingleSourcePath(ctx)
271
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800272 // TODO: Install or embed JNI libraries
273
274 // Uncompress JNI libraries in the apk
275 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
276 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
277
Spandan Dasd1fac642021-05-18 17:01:41 +0000278 var pathFragments []string
279 relInstallPath := String(a.properties.Relative_install_path)
Bill Peckhama036da92021-01-08 16:09:09 -0800280
281 if a.isPrebuiltFrameworkRes() {
282 // framework-res.apk is installed as system/framework/framework-res.apk
Spandan Dasd1fac642021-05-18 17:01:41 +0000283 if relInstallPath != "" {
284 ctx.PropertyErrorf("relative_install_path", "Relative_install_path cannot be set for framework-res")
285 }
286 pathFragments = []string{"framework"}
Bill Peckhama036da92021-01-08 16:09:09 -0800287 a.preprocessed = true
288 } else if Bool(a.properties.Privileged) {
Spandan Dasd1fac642021-05-18 17:01:41 +0000289 pathFragments = []string{"priv-app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800290 } else if ctx.InstallInTestcases() {
Spandan Dasd1fac642021-05-18 17:01:41 +0000291 pathFragments = []string{relInstallPath, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800292 } else {
Spandan Dasd1fac642021-05-18 17:01:41 +0000293 pathFragments = []string{"app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800294 }
295
Spandan Dasd1fac642021-05-18 17:01:41 +0000296 installDir := android.PathForModuleInstall(ctx, pathFragments...)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000297 a.dexpreopter.isApp = true
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800298 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
299 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
300 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
301
302 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
303 a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
304
Ulya Trafimovichfe927a22021-02-26 14:36:48 +0000305 if a.usesLibrary.enforceUsesLibraries() {
306 srcApk = a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
307 }
308
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800309 a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
310 if a.dexpreopter.uncompressedDex {
311 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
Cole Faust4ec178c2023-01-13 12:03:38 -0800312 ctx.Build(pctx, android.BuildParams{
313 Rule: uncompressDexRule,
314 Input: jnisUncompressed,
315 Output: dexUncompressed,
316 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800317 jnisUncompressed = dexUncompressed
318 }
319
320 apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
321
322 // TODO: Handle EXTERNAL
323
324 // Sign or align the package if package has not been preprocessed
Bill Peckhama036da92021-01-08 16:09:09 -0800325
326 if a.isPrebuiltFrameworkRes() {
327 a.outputFile = srcApk
Colin Crossbc2c8a72022-09-14 12:45:42 -0700328 a.certificate, certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Bill Peckhama036da92021-01-08 16:09:09 -0800329 if len(certificates) != 1 {
330 ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
331 }
Bill Peckhama036da92021-01-08 16:09:09 -0800332 } else if a.preprocessed {
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800333 a.outputFile = srcApk
334 a.certificate = PresignedCertificate
335 } else if !Bool(a.properties.Presigned) {
336 // If the certificate property is empty at this point, default_dev_cert must be set to true.
337 // Which makes processMainCert's behavior for the empty cert string WAI.
Colin Crossbc2c8a72022-09-14 12:45:42 -0700338 a.certificate, certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800339 signed := android.PathForModuleOut(ctx, "signed", apkFilename)
340 var lineageFile android.Path
341 if lineage := String(a.properties.Lineage); lineage != "" {
342 lineageFile = android.PathForModuleSrc(ctx, lineage)
343 }
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -0400344
345 rotationMinSdkVersion := String(a.properties.RotationMinSdkVersion)
346
347 SignAppPackage(ctx, signed, jnisUncompressed, certificates, nil, lineageFile, rotationMinSdkVersion)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800348 a.outputFile = signed
349 } else {
350 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
351 TransformZipAlign(ctx, alignedApk, jnisUncompressed)
352 a.outputFile = alignedApk
353 a.certificate = PresignedCertificate
354 }
355
356 // TODO: Optionally compress the output apk.
357
358 if apexInfo.IsForPlatform() {
359 a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
Wei Li340ee8e2022-03-18 17:33:24 -0700360 artifactPath := android.PathForModuleSrc(ctx, *a.properties.Apk)
361 a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800362 }
363
364 // TODO: androidmk converter jni libs
365}
366
367func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
368 return &a.prebuilt
369}
370
371func (a *AndroidAppImport) Name() string {
372 return a.prebuilt.Name(a.ModuleBase.Name())
373}
374
375func (a *AndroidAppImport) OutputFile() android.Path {
376 return a.outputFile
377}
378
379func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
380 return nil
381}
382
383func (a *AndroidAppImport) Certificate() Certificate {
384 return a.certificate
385}
386
Wei Li340ee8e2022-03-18 17:33:24 -0700387func (a *AndroidAppImport) ProvenanceMetaDataFile() android.OutputPath {
388 return a.provenanceMetaDataFile
389}
390
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800391var dpiVariantGroupType reflect.Type
392var archVariantGroupType reflect.Type
393var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
394
395func initAndroidAppImportVariantGroupTypes() {
396 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
397
398 archNames := make([]string, len(android.ArchTypeList()))
399 for i, archType := range android.ArchTypeList() {
400 archNames[i] = archType.Name
401 }
402 archVariantGroupType = createVariantGroupType(archNames, "Arch")
403}
404
405// Populates all variant struct properties at creation time.
406func (a *AndroidAppImport) populateAllVariantStructs() {
407 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
408 a.AddProperties(a.dpiVariants)
409
410 a.archVariants = reflect.New(archVariantGroupType).Interface()
411 a.AddProperties(a.archVariants)
412}
413
414func (a *AndroidAppImport) Privileged() bool {
415 return Bool(a.properties.Privileged)
416}
417
418func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
419 // android_app_import might have extra dependencies via uses_libs property.
420 // Don't track the dependency as we don't automatically add those libraries
421 // to the classpath. It should be explicitly added to java_libs property of APEX
422 return false
423}
424
Jiyong Park92315372021-04-02 08:45:46 +0900425func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
426 return android.SdkSpecPrivate
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800427}
428
Jiyong Park92315372021-04-02 08:45:46 +0900429func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
430 return android.SdkSpecPrivate
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800431}
432
Colin Cross8355c152021-08-10 19:24:07 -0700433func (a *AndroidAppImport) LintDepSets() LintDepSets {
434 return LintDepSets{}
435}
436
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800437var _ android.ApexModule = (*AndroidAppImport)(nil)
438
439// Implements android.ApexModule
440func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
441 sdkVersion android.ApiLevel) error {
442 // Do not check for prebuilts against the min_sdk_version of enclosing APEX
443 return nil
444}
445
446func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
447 props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
448
449 variantFields := make([]reflect.StructField, len(variants))
450 for i, variant := range variants {
451 variantFields[i] = reflect.StructField{
452 Name: proptools.FieldNameForProperty(variant),
453 Type: props,
454 }
455 }
456
457 variantGroupStruct := reflect.StructOf(variantFields)
458 return reflect.StructOf([]reflect.StructField{
459 {
460 Name: variantGroupName,
461 Type: variantGroupStruct,
462 },
463 })
464}
465
466// android_app_import imports a prebuilt apk with additional processing specified in the module.
467// DPI-specific apk source files can be specified using dpi_variants. Example:
468//
Colin Crossd079e0b2022-08-16 10:27:33 -0700469// android_app_import {
470// name: "example_import",
471// apk: "prebuilts/example.apk",
472// dpi_variants: {
473// mdpi: {
474// apk: "prebuilts/example_mdpi.apk",
475// },
476// xhdpi: {
477// apk: "prebuilts/example_xhdpi.apk",
478// },
479// },
480// presigned: true,
481// }
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800482func AndroidAppImportFactory() android.Module {
483 module := &AndroidAppImport{}
484 module.AddProperties(&module.properties)
485 module.AddProperties(&module.dexpreoptProperties)
486 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
487 module.populateAllVariantStructs()
488 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
489 module.processVariants(ctx)
490 })
491
492 android.InitApexModule(module)
493 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
494 android.InitDefaultableModule(module)
495 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
496
Ulya Trafimovich22890c42021-01-05 12:04:17 +0000497 module.usesLibrary.enforce = true
498
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800499 return module
500}
501
502type androidTestImportProperties struct {
503 // Whether the prebuilt apk can be installed without additional processing. Default is false.
504 Preprocessed *bool
505}
506
507type AndroidTestImport struct {
508 AndroidAppImport
509
Jiyong Park2f83b312022-10-20 20:18:35 +0900510 testProperties struct {
511 // list of compatibility suites (for example "cts", "vts") that the module should be
512 // installed into.
513 Test_suites []string `android:"arch_variant"`
514
515 // list of files or filegroup modules that provide data that should be installed alongside
516 // the test
517 Data []string `android:"path"`
518
519 // Install the test into a folder named for the module in all test suites.
520 Per_testcase_directory *bool
521 }
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800522
523 testImportProperties androidTestImportProperties
524
525 data android.Paths
526}
527
528func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
529 a.preprocessed = Bool(a.testImportProperties.Preprocessed)
530
531 a.generateAndroidBuildActions(ctx)
532
533 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
534}
535
536func (a *AndroidTestImport) InstallInTestcases() bool {
537 return true
538}
539
540// android_test_import imports a prebuilt test apk with additional processing specified in the
541// module. DPI or arch variant configurations can be made as with android_app_import.
542func AndroidTestImportFactory() android.Module {
543 module := &AndroidTestImport{}
544 module.AddProperties(&module.properties)
545 module.AddProperties(&module.dexpreoptProperties)
546 module.AddProperties(&module.testProperties)
547 module.AddProperties(&module.testImportProperties)
548 module.populateAllVariantStructs()
549 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
550 module.processVariants(ctx)
551 })
552
553 module.dexpreopter.isTest = true
554
555 android.InitApexModule(module)
556 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
557 android.InitDefaultableModule(module)
558 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
559
560 return module
561}