blob: 6e603c912310b990ea3ccbd4a695e86f3924f627 [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 (
20 "reflect"
21
22 "github.com/google/blueprint/proptools"
23
24 "android/soong/android"
Wei Li340ee8e2022-03-18 17:33:24 -070025 "android/soong/provenance"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080026)
27
28func init() {
29 RegisterAppImportBuildComponents(android.InitRegistrationContext)
30
31 initAndroidAppImportVariantGroupTypes()
32}
33
34func RegisterAppImportBuildComponents(ctx android.RegistrationContext) {
35 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
36 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
37}
38
39type AndroidAppImport struct {
40 android.ModuleBase
41 android.DefaultableModuleBase
42 android.ApexModuleBase
43 prebuilt android.Prebuilt
44
45 properties AndroidAppImportProperties
46 dpiVariants interface{}
47 archVariants interface{}
48
49 outputFile android.Path
50 certificate Certificate
51
52 dexpreopter
53
54 usesLibrary usesLibrary
55
56 preprocessed bool
57
58 installPath android.InstallPath
59
60 hideApexVariantFromMake bool
Wei Li340ee8e2022-03-18 17:33:24 -070061
62 provenanceMetaDataFile android.OutputPath
Jaewoong Jungf9b44652020-12-21 12:29:12 -080063}
64
65type AndroidAppImportProperties struct {
66 // A prebuilt apk to import
Jooyung Hanf05ca9c2021-06-28 21:48:51 +090067 Apk *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -080068
69 // The name of a certificate in the default certificate directory or an android_app_certificate
70 // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
71 Certificate *string
72
Jaewoong Jung25ae8de2021-03-08 17:37:46 -080073 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
74 Additional_certificates []string
75
Jaewoong Jungf9b44652020-12-21 12:29:12 -080076 // Set this flag to true if the prebuilt apk is already signed. The certificate property must not
77 // be set for presigned modules.
78 Presigned *bool
79
Jaewoong Jung1c1b6e62021-03-09 15:02:31 -080080 // Name of the signing certificate lineage file or filegroup module.
81 Lineage *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -080082
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -040083 // For overriding the --rotation-min-sdk-version property of apksig
84 RotationMinSdkVersion *string
85
Jaewoong Jungf9b44652020-12-21 12:29:12 -080086 // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
87 // need to either specify a specific certificate or be presigned.
88 Default_dev_cert *bool
89
90 // Specifies that this app should be installed to the priv-app directory,
91 // where the system will grant it additional privileges not available to
92 // normal apps.
93 Privileged *bool
94
95 // Names of modules to be overridden. Listed modules can only be other binaries
96 // (in Make or Soong).
97 // This does not completely prevent installation of the overridden binaries, but if both
98 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
99 // from PRODUCT_PACKAGES.
100 Overrides []string
101
102 // Optional name for the installed app. If unspecified, it is derived from the module name.
103 Filename *string
Bill Peckhama036da92021-01-08 16:09:09 -0800104
105 // If set, create package-export.apk, which other packages can
106 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
107 Export_package_resources *bool
Spandan Dasd1fac642021-05-18 17:01:41 +0000108
109 // Optional. Install to a subdirectory of the default install path for the module
110 Relative_install_path *string
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800111}
112
113func (a *AndroidAppImport) IsInstallable() bool {
114 return true
115}
116
117// Updates properties with variant-specific values.
118func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
119 config := ctx.Config()
120
121 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
122 // Try DPI variant matches in the reverse-priority order so that the highest priority match
123 // overwrites everything else.
124 // TODO(jungjw): Can we optimize this by making it priority order?
125 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
126 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
127 }
128 if config.ProductAAPTPreferredConfig() != "" {
129 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
130 }
131
132 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
133 archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType
134 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
135
136 if String(a.properties.Apk) == "" {
137 // Disable this module since the apk property is still empty after processing all matching
138 // variants. This likely means there is no matching variant, and the default variant doesn't
139 // have an apk property value either.
140 a.Disable()
141 }
142}
143
144func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
145 dst interface{}, variantGroup reflect.Value, variant string) {
146 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
147 if !src.IsValid() {
148 return
149 }
150
151 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
152 if err != nil {
153 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
154 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
155 } else {
156 panic(err)
157 }
158 }
159}
160
Bill Peckhama036da92021-01-08 16:09:09 -0800161func (a *AndroidAppImport) isPrebuiltFrameworkRes() bool {
162 return a.Name() == "prebuilt_framework-res"
163}
164
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800165func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
166 cert := android.SrcIsModule(String(a.properties.Certificate))
167 if cert != "" {
168 ctx.AddDependency(ctx.Module(), certificateTag, cert)
169 }
170
Jaewoong Jung25ae8de2021-03-08 17:37:46 -0800171 for _, cert := range a.properties.Additional_certificates {
172 cert = android.SrcIsModule(cert)
173 if cert != "" {
174 ctx.AddDependency(ctx.Module(), certificateTag, cert)
175 } else {
176 ctx.PropertyErrorf("additional_certificates",
177 `must be names of android_app_certificate modules in the form ":module"`)
178 }
179 }
180
Bill Peckhama036da92021-01-08 16:09:09 -0800181 a.usesLibrary.deps(ctx, !a.isPrebuiltFrameworkRes())
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800182}
183
184func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
185 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
186 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
187 // with them may invalidate pre-existing signature data.
188 if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || a.preprocessed) {
189 ctx.Build(pctx, android.BuildParams{
190 Rule: android.Cp,
191 Output: outputPath,
192 Input: inputPath,
193 })
194 return
195 }
196 rule := android.NewRuleBuilder(pctx, ctx)
197 rule.Command().
198 Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
199 BuiltTool("zip2zip").
200 FlagWithInput("-i ", inputPath).
201 FlagWithOutput("-o ", outputPath).
202 FlagWithArg("-0 ", "'lib/**/*.so'").
203 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
204 rule.Build("uncompress-embedded-jni-libs", "Uncompress embedded JIN libs")
205}
206
207// Returns whether this module should have the dex file stored uncompressed in the APK.
208func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
209 if ctx.Config().UnbundledBuild() || a.preprocessed {
210 return false
211 }
212
Ulya Trafimovich0061c0d2021-09-01 15:40:38 +0100213 // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false.
214 if a.Privileged() {
215 return ctx.Config().UncompressPrivAppDex()
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800216 }
217
218 return shouldUncompressDex(ctx, &a.dexpreopter)
219}
220
221func (a *AndroidAppImport) uncompressDex(
222 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
223 rule := android.NewRuleBuilder(pctx, ctx)
224 rule.Command().
225 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
226 BuiltTool("zip2zip").
227 FlagWithInput("-i ", inputPath).
228 FlagWithOutput("-o ", outputPath).
229 FlagWithArg("-0 ", "'classes*.dex'").
230 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
231 rule.Build("uncompress-dex", "Uncompress dex files")
232}
233
234func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
235 a.generateAndroidBuildActions(ctx)
236}
237
238func (a *AndroidAppImport) InstallApkName() string {
239 return a.BaseModuleName()
240}
241
242func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
243 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
244 if !apexInfo.IsForPlatform() {
245 a.hideApexVariantFromMake = true
246 }
247
248 numCertPropsSet := 0
249 if String(a.properties.Certificate) != "" {
250 numCertPropsSet++
251 }
252 if Bool(a.properties.Presigned) {
253 numCertPropsSet++
254 }
255 if Bool(a.properties.Default_dev_cert) {
256 numCertPropsSet++
257 }
258 if numCertPropsSet != 1 {
259 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
260 }
261
Sam Delmerico82602492022-06-10 17:05:42 +0000262 _, _, certificates := collectAppDeps(ctx, a, false, false)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800263
264 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
265 // TODO: LOCAL_PACKAGE_SPLITS
266
267 srcApk := a.prebuilt.SingleSourcePath(ctx)
268
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800269 // TODO: Install or embed JNI libraries
270
271 // Uncompress JNI libraries in the apk
272 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
273 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
274
Spandan Dasd1fac642021-05-18 17:01:41 +0000275 var pathFragments []string
276 relInstallPath := String(a.properties.Relative_install_path)
Bill Peckhama036da92021-01-08 16:09:09 -0800277
278 if a.isPrebuiltFrameworkRes() {
279 // framework-res.apk is installed as system/framework/framework-res.apk
Spandan Dasd1fac642021-05-18 17:01:41 +0000280 if relInstallPath != "" {
281 ctx.PropertyErrorf("relative_install_path", "Relative_install_path cannot be set for framework-res")
282 }
283 pathFragments = []string{"framework"}
Bill Peckhama036da92021-01-08 16:09:09 -0800284 a.preprocessed = true
285 } else if Bool(a.properties.Privileged) {
Spandan Dasd1fac642021-05-18 17:01:41 +0000286 pathFragments = []string{"priv-app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800287 } else if ctx.InstallInTestcases() {
Spandan Dasd1fac642021-05-18 17:01:41 +0000288 pathFragments = []string{relInstallPath, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800289 } else {
Spandan Dasd1fac642021-05-18 17:01:41 +0000290 pathFragments = []string{"app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800291 }
292
Spandan Dasd1fac642021-05-18 17:01:41 +0000293 installDir := android.PathForModuleInstall(ctx, pathFragments...)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000294 a.dexpreopter.isApp = true
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800295 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
296 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
297 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
298
299 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
300 a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
301
Ulya Trafimovichfe927a22021-02-26 14:36:48 +0000302 if a.usesLibrary.enforceUsesLibraries() {
303 srcApk = a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
304 }
305
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800306 a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
307 if a.dexpreopter.uncompressedDex {
308 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
309 a.uncompressDex(ctx, jnisUncompressed, dexUncompressed.OutputPath)
310 jnisUncompressed = dexUncompressed
311 }
312
313 apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
314
315 // TODO: Handle EXTERNAL
316
317 // Sign or align the package if package has not been preprocessed
Bill Peckhama036da92021-01-08 16:09:09 -0800318
319 if a.isPrebuiltFrameworkRes() {
320 a.outputFile = srcApk
Colin Crossbc2c8a72022-09-14 12:45:42 -0700321 a.certificate, certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Bill Peckhama036da92021-01-08 16:09:09 -0800322 if len(certificates) != 1 {
323 ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
324 }
Bill Peckhama036da92021-01-08 16:09:09 -0800325 } else if a.preprocessed {
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800326 a.outputFile = srcApk
327 a.certificate = PresignedCertificate
328 } else if !Bool(a.properties.Presigned) {
329 // If the certificate property is empty at this point, default_dev_cert must be set to true.
330 // Which makes processMainCert's behavior for the empty cert string WAI.
Colin Crossbc2c8a72022-09-14 12:45:42 -0700331 a.certificate, certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800332 signed := android.PathForModuleOut(ctx, "signed", apkFilename)
333 var lineageFile android.Path
334 if lineage := String(a.properties.Lineage); lineage != "" {
335 lineageFile = android.PathForModuleSrc(ctx, lineage)
336 }
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -0400337
338 rotationMinSdkVersion := String(a.properties.RotationMinSdkVersion)
339
340 SignAppPackage(ctx, signed, jnisUncompressed, certificates, nil, lineageFile, rotationMinSdkVersion)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800341 a.outputFile = signed
342 } else {
343 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
344 TransformZipAlign(ctx, alignedApk, jnisUncompressed)
345 a.outputFile = alignedApk
346 a.certificate = PresignedCertificate
347 }
348
349 // TODO: Optionally compress the output apk.
350
351 if apexInfo.IsForPlatform() {
352 a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
Wei Li340ee8e2022-03-18 17:33:24 -0700353 artifactPath := android.PathForModuleSrc(ctx, *a.properties.Apk)
354 a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800355 }
356
357 // TODO: androidmk converter jni libs
358}
359
360func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
361 return &a.prebuilt
362}
363
364func (a *AndroidAppImport) Name() string {
365 return a.prebuilt.Name(a.ModuleBase.Name())
366}
367
368func (a *AndroidAppImport) OutputFile() android.Path {
369 return a.outputFile
370}
371
372func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
373 return nil
374}
375
376func (a *AndroidAppImport) Certificate() Certificate {
377 return a.certificate
378}
379
Wei Li340ee8e2022-03-18 17:33:24 -0700380func (a *AndroidAppImport) ProvenanceMetaDataFile() android.OutputPath {
381 return a.provenanceMetaDataFile
382}
383
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800384var dpiVariantGroupType reflect.Type
385var archVariantGroupType reflect.Type
386var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
387
388func initAndroidAppImportVariantGroupTypes() {
389 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
390
391 archNames := make([]string, len(android.ArchTypeList()))
392 for i, archType := range android.ArchTypeList() {
393 archNames[i] = archType.Name
394 }
395 archVariantGroupType = createVariantGroupType(archNames, "Arch")
396}
397
398// Populates all variant struct properties at creation time.
399func (a *AndroidAppImport) populateAllVariantStructs() {
400 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
401 a.AddProperties(a.dpiVariants)
402
403 a.archVariants = reflect.New(archVariantGroupType).Interface()
404 a.AddProperties(a.archVariants)
405}
406
407func (a *AndroidAppImport) Privileged() bool {
408 return Bool(a.properties.Privileged)
409}
410
411func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
412 // android_app_import might have extra dependencies via uses_libs property.
413 // Don't track the dependency as we don't automatically add those libraries
414 // to the classpath. It should be explicitly added to java_libs property of APEX
415 return false
416}
417
Jiyong Park92315372021-04-02 08:45:46 +0900418func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
419 return android.SdkSpecPrivate
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800420}
421
Jiyong Park92315372021-04-02 08:45:46 +0900422func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
423 return android.SdkSpecPrivate
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800424}
425
Colin Cross8355c152021-08-10 19:24:07 -0700426func (a *AndroidAppImport) LintDepSets() LintDepSets {
427 return LintDepSets{}
428}
429
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800430var _ android.ApexModule = (*AndroidAppImport)(nil)
431
432// Implements android.ApexModule
433func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
434 sdkVersion android.ApiLevel) error {
435 // Do not check for prebuilts against the min_sdk_version of enclosing APEX
436 return nil
437}
438
439func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
440 props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
441
442 variantFields := make([]reflect.StructField, len(variants))
443 for i, variant := range variants {
444 variantFields[i] = reflect.StructField{
445 Name: proptools.FieldNameForProperty(variant),
446 Type: props,
447 }
448 }
449
450 variantGroupStruct := reflect.StructOf(variantFields)
451 return reflect.StructOf([]reflect.StructField{
452 {
453 Name: variantGroupName,
454 Type: variantGroupStruct,
455 },
456 })
457}
458
459// android_app_import imports a prebuilt apk with additional processing specified in the module.
460// DPI-specific apk source files can be specified using dpi_variants. Example:
461//
Colin Crossd079e0b2022-08-16 10:27:33 -0700462// android_app_import {
463// name: "example_import",
464// apk: "prebuilts/example.apk",
465// dpi_variants: {
466// mdpi: {
467// apk: "prebuilts/example_mdpi.apk",
468// },
469// xhdpi: {
470// apk: "prebuilts/example_xhdpi.apk",
471// },
472// },
473// presigned: true,
474// }
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800475func AndroidAppImportFactory() android.Module {
476 module := &AndroidAppImport{}
477 module.AddProperties(&module.properties)
478 module.AddProperties(&module.dexpreoptProperties)
479 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
480 module.populateAllVariantStructs()
481 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
482 module.processVariants(ctx)
483 })
484
485 android.InitApexModule(module)
486 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
487 android.InitDefaultableModule(module)
488 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
489
Ulya Trafimovich22890c42021-01-05 12:04:17 +0000490 module.usesLibrary.enforce = true
491
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800492 return module
493}
494
495type androidTestImportProperties struct {
496 // Whether the prebuilt apk can be installed without additional processing. Default is false.
497 Preprocessed *bool
498}
499
500type AndroidTestImport struct {
501 AndroidAppImport
502
503 testProperties testProperties
504
505 testImportProperties androidTestImportProperties
506
507 data android.Paths
508}
509
510func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
511 a.preprocessed = Bool(a.testImportProperties.Preprocessed)
512
513 a.generateAndroidBuildActions(ctx)
514
515 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
516}
517
518func (a *AndroidTestImport) InstallInTestcases() bool {
519 return true
520}
521
522// android_test_import imports a prebuilt test apk with additional processing specified in the
523// module. DPI or arch variant configurations can be made as with android_app_import.
524func AndroidTestImportFactory() android.Module {
525 module := &AndroidTestImport{}
526 module.AddProperties(&module.properties)
527 module.AddProperties(&module.dexpreoptProperties)
528 module.AddProperties(&module.testProperties)
529 module.AddProperties(&module.testImportProperties)
530 module.populateAllVariantStructs()
531 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
532 module.processVariants(ctx)
533 })
534
535 module.dexpreopter.isTest = true
536
537 android.InitApexModule(module)
538 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
539 android.InitDefaultableModule(module)
540 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
541
542 return module
543}