blob: 9c01960390225e33638877ad606b989d5a610341 [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
Cole Faustd5806132023-04-13 15:43:53 -070022 "github.com/google/blueprint"
23
Jaewoong Jungf9b44652020-12-21 12:29:12 -080024 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
Wei Li340ee8e2022-03-18 17:33:24 -070027 "android/soong/provenance"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080028)
29
30func init() {
31 RegisterAppImportBuildComponents(android.InitRegistrationContext)
32
33 initAndroidAppImportVariantGroupTypes()
34}
35
Cole Faust4ec178c2023-01-13 12:03:38 -080036var (
37 uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{
38 Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` +
39 `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` +
40 `; else cp -f $in $out; fi`,
41 CommandDeps: []string{"${config.Zip2ZipCmd}"},
42 Description: "Uncompress embedded JNI libs",
43 })
44
45 uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{
46 Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` +
47 `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` +
48 `; else cp -f $in $out; fi`,
49 CommandDeps: []string{"${config.Zip2ZipCmd}"},
50 Description: "Uncompress dex files",
51 })
Cole Faust2f1da162023-04-17 15:06:56 -070052
53 checkJniAndDexLibsAreUncompressedRule = pctx.AndroidStaticRule("check-jni-and-dex-libs-are-uncompressed", blueprint.RuleParams{
54 // grep -v ' stor ' will search for lines that don't have ' stor '. stor means the file is stored uncompressed
55 Command: "if (zipinfo $in 'lib/*.so' '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then " +
56 "echo $in: Contains compressed JNI libraries and/or dex files >&2;" +
57 "exit 1; " +
58 "else " +
59 "touch $out; " +
60 "fi",
61 Description: "Check for compressed JNI libs or dex files",
62 })
Cole Faust4ec178c2023-01-13 12:03:38 -080063)
64
Jaewoong Jungf9b44652020-12-21 12:29:12 -080065func RegisterAppImportBuildComponents(ctx android.RegistrationContext) {
66 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
67 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
68}
69
70type AndroidAppImport struct {
71 android.ModuleBase
72 android.DefaultableModuleBase
73 android.ApexModuleBase
74 prebuilt android.Prebuilt
75
76 properties AndroidAppImportProperties
77 dpiVariants interface{}
78 archVariants interface{}
79
80 outputFile android.Path
81 certificate Certificate
82
83 dexpreopter
84
85 usesLibrary usesLibrary
86
Jaewoong Jungf9b44652020-12-21 12:29:12 -080087 installPath android.InstallPath
88
89 hideApexVariantFromMake bool
Wei Li340ee8e2022-03-18 17:33:24 -070090
91 provenanceMetaDataFile android.OutputPath
Jaewoong Jungf9b44652020-12-21 12:29:12 -080092}
93
94type AndroidAppImportProperties struct {
95 // A prebuilt apk to import
Jooyung Hanf05ca9c2021-06-28 21:48:51 +090096 Apk *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -080097
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.
100 Certificate *string
101
Jaewoong Jung25ae8de2021-03-08 17:37:46 -0800102 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
103 Additional_certificates []string
104
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800105 // 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 Jung1c1b6e62021-03-09 15:02:31 -0800109 // Name of the signing certificate lineage file or filegroup module.
110 Lineage *string `android:"path"`
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800111
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -0400112 // For overriding the --rotation-min-sdk-version property of apksig
113 RotationMinSdkVersion *string
114
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800115 // 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 Peckhama036da92021-01-08 16:09:09 -0800133
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 Dasd1fac642021-05-18 17:01:41 +0000137
138 // Optional. Install to a subdirectory of the default install path for the module
139 Relative_install_path *string
Cole Faust2f1da162023-04-17 15:06:56 -0700140
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
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800147}
148
149func (a *AndroidAppImport) IsInstallable() bool {
150 return true
151}
152
153// Updates properties with variant-specific values.
154func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
155 config := ctx.Config()
156
157 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
158 // Try DPI variant matches in the reverse-priority order so that the highest priority match
159 // overwrites everything else.
160 // TODO(jungjw): Can we optimize this by making it priority order?
161 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
162 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
163 }
164 if config.ProductAAPTPreferredConfig() != "" {
165 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
166 }
167
168 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
169 archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType
170 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
171
172 if String(a.properties.Apk) == "" {
173 // Disable this module since the apk property is still empty after processing all matching
174 // variants. This likely means there is no matching variant, and the default variant doesn't
175 // have an apk property value either.
176 a.Disable()
177 }
178}
179
180func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
181 dst interface{}, variantGroup reflect.Value, variant string) {
182 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
183 if !src.IsValid() {
184 return
185 }
186
187 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
188 if err != nil {
189 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
190 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
191 } else {
192 panic(err)
193 }
194 }
195}
196
197func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
198 cert := android.SrcIsModule(String(a.properties.Certificate))
199 if cert != "" {
200 ctx.AddDependency(ctx.Module(), certificateTag, cert)
201 }
202
Jaewoong Jung25ae8de2021-03-08 17:37:46 -0800203 for _, cert := range a.properties.Additional_certificates {
204 cert = android.SrcIsModule(cert)
205 if cert != "" {
206 ctx.AddDependency(ctx.Module(), certificateTag, cert)
207 } else {
208 ctx.PropertyErrorf("additional_certificates",
209 `must be names of android_app_certificate modules in the form ":module"`)
210 }
211 }
212
Cole Faustd5806132023-04-13 15:43:53 -0700213 a.usesLibrary.deps(ctx, true)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800214}
215
216func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
217 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
218 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
219 // with them may invalidate pre-existing signature data.
Cole Faust2f1da162023-04-17 15:06:56 -0700220 if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || Bool(a.properties.Preprocessed)) {
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800221 ctx.Build(pctx, android.BuildParams{
222 Rule: android.Cp,
223 Output: outputPath,
224 Input: inputPath,
225 })
226 return
227 }
Cole Faust4ec178c2023-01-13 12:03:38 -0800228
229 ctx.Build(pctx, android.BuildParams{
230 Rule: uncompressEmbeddedJniLibsRule,
231 Input: inputPath,
232 Output: outputPath,
233 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800234}
235
236// Returns whether this module should have the dex file stored uncompressed in the APK.
237func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
Cole Faust2f1da162023-04-17 15:06:56 -0700238 if ctx.Config().UnbundledBuild() || proptools.Bool(a.properties.Preprocessed) {
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800239 return false
240 }
241
Ulya Trafimovich0061c0d2021-09-01 15:40:38 +0100242 // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false.
243 if a.Privileged() {
244 return ctx.Config().UncompressPrivAppDex()
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800245 }
246
247 return shouldUncompressDex(ctx, &a.dexpreopter)
248}
249
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800250func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
251 a.generateAndroidBuildActions(ctx)
252}
253
254func (a *AndroidAppImport) InstallApkName() string {
255 return a.BaseModuleName()
256}
257
258func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faustd5806132023-04-13 15:43:53 -0700259 if a.Name() == "prebuilt_framework-res" {
260 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.")
261 }
262
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800263 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
264 if !apexInfo.IsForPlatform() {
265 a.hideApexVariantFromMake = true
266 }
267
268 numCertPropsSet := 0
269 if String(a.properties.Certificate) != "" {
270 numCertPropsSet++
271 }
272 if Bool(a.properties.Presigned) {
273 numCertPropsSet++
274 }
275 if Bool(a.properties.Default_dev_cert) {
276 numCertPropsSet++
277 }
278 if numCertPropsSet != 1 {
279 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
280 }
281
Sam Delmerico82602492022-06-10 17:05:42 +0000282 _, _, certificates := collectAppDeps(ctx, a, false, false)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800283
284 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
285 // TODO: LOCAL_PACKAGE_SPLITS
286
287 srcApk := a.prebuilt.SingleSourcePath(ctx)
288
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800289 // TODO: Install or embed JNI libraries
290
291 // Uncompress JNI libraries in the apk
292 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
293 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
294
Spandan Dasd1fac642021-05-18 17:01:41 +0000295 var pathFragments []string
296 relInstallPath := String(a.properties.Relative_install_path)
Bill Peckhama036da92021-01-08 16:09:09 -0800297
Cole Faustd5806132023-04-13 15:43:53 -0700298 if Bool(a.properties.Privileged) {
Spandan Dasd1fac642021-05-18 17:01:41 +0000299 pathFragments = []string{"priv-app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800300 } else if ctx.InstallInTestcases() {
Spandan Dasd1fac642021-05-18 17:01:41 +0000301 pathFragments = []string{relInstallPath, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800302 } else {
Spandan Dasd1fac642021-05-18 17:01:41 +0000303 pathFragments = []string{"app", relInstallPath, a.BaseModuleName()}
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800304 }
305
Spandan Dasd1fac642021-05-18 17:01:41 +0000306 installDir := android.PathForModuleInstall(ctx, pathFragments...)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000307 a.dexpreopter.isApp = true
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800308 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
309 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
310 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
311
312 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
313 a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
314
Ulya Trafimovichfe927a22021-02-26 14:36:48 +0000315 if a.usesLibrary.enforceUsesLibraries() {
Cole Faust2f1da162023-04-17 15:06:56 -0700316 a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
Ulya Trafimovichfe927a22021-02-26 14:36:48 +0000317 }
318
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800319 a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
320 if a.dexpreopter.uncompressedDex {
321 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
Cole Faust4ec178c2023-01-13 12:03:38 -0800322 ctx.Build(pctx, android.BuildParams{
323 Rule: uncompressDexRule,
324 Input: jnisUncompressed,
325 Output: dexUncompressed,
326 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800327 jnisUncompressed = dexUncompressed
328 }
329
330 apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
331
332 // TODO: Handle EXTERNAL
333
334 // Sign or align the package if package has not been preprocessed
Bill Peckhama036da92021-01-08 16:09:09 -0800335
Cole Faust2f1da162023-04-17 15:06:56 -0700336 if proptools.Bool(a.properties.Preprocessed) {
337 output := srcApk
Cole Faustccb20f42023-05-04 12:38:24 -0700338 if !proptools.Bool(a.properties.Skip_preprocessed_apk_checks) {
339 writableOutput := android.PathForModuleOut(ctx, "validated-prebuilt", apkFilename)
340 a.validatePreprocessedApk(ctx, srcApk, writableOutput)
341 output = writableOutput
342 }
Cole Faust2f1da162023-04-17 15:06:56 -0700343 a.outputFile = output
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800344 a.certificate = PresignedCertificate
345 } else if !Bool(a.properties.Presigned) {
346 // If the certificate property is empty at this point, default_dev_cert must be set to true.
347 // Which makes processMainCert's behavior for the empty cert string WAI.
Colin Crossbc2c8a72022-09-14 12:45:42 -0700348 a.certificate, certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800349 signed := android.PathForModuleOut(ctx, "signed", apkFilename)
350 var lineageFile android.Path
351 if lineage := String(a.properties.Lineage); lineage != "" {
352 lineageFile = android.PathForModuleSrc(ctx, lineage)
353 }
Rupert Shuttleworth8eab8692021-11-03 10:39:39 -0400354
355 rotationMinSdkVersion := String(a.properties.RotationMinSdkVersion)
356
357 SignAppPackage(ctx, signed, jnisUncompressed, certificates, nil, lineageFile, rotationMinSdkVersion)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800358 a.outputFile = signed
359 } else {
360 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
361 TransformZipAlign(ctx, alignedApk, jnisUncompressed)
362 a.outputFile = alignedApk
363 a.certificate = PresignedCertificate
364 }
365
366 // TODO: Optionally compress the output apk.
367
368 if apexInfo.IsForPlatform() {
369 a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
Wei Li340ee8e2022-03-18 17:33:24 -0700370 artifactPath := android.PathForModuleSrc(ctx, *a.properties.Apk)
371 a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800372 }
373
374 // TODO: androidmk converter jni libs
375}
376
Cole Faust2f1da162023-04-17 15:06:56 -0700377func (a *AndroidAppImport) validatePreprocessedApk(ctx android.ModuleContext, srcApk android.Path, dstApk android.WritablePath) {
378 alignmentStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "alignment.stamp")
379 ctx.Build(pctx, android.BuildParams{
380 Rule: checkZipAlignment,
381 Input: srcApk,
382 Output: alignmentStamp,
383 })
384 compressionStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "compression.stamp")
385 ctx.Build(pctx, android.BuildParams{
386 Rule: checkJniAndDexLibsAreUncompressedRule,
387 Input: srcApk,
388 Output: compressionStamp,
389 })
390 ctx.Build(pctx, android.BuildParams{
391 Rule: android.Cp,
392 Input: srcApk,
393 Output: dstApk,
394 Validations: []android.Path{
395 alignmentStamp,
396 compressionStamp,
397 },
398 })
399}
400
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800401func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
402 return &a.prebuilt
403}
404
405func (a *AndroidAppImport) Name() string {
406 return a.prebuilt.Name(a.ModuleBase.Name())
407}
408
409func (a *AndroidAppImport) OutputFile() android.Path {
410 return a.outputFile
411}
412
413func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
414 return nil
415}
416
417func (a *AndroidAppImport) Certificate() Certificate {
418 return a.certificate
419}
420
Wei Li340ee8e2022-03-18 17:33:24 -0700421func (a *AndroidAppImport) ProvenanceMetaDataFile() android.OutputPath {
422 return a.provenanceMetaDataFile
423}
424
Andrei Onea580636b2022-08-17 16:53:46 +0000425func (a *AndroidAppImport) PrivAppAllowlist() android.OptionalPath {
426 return android.OptionalPath{}
427}
428
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800429var dpiVariantGroupType reflect.Type
430var archVariantGroupType reflect.Type
431var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
432
433func initAndroidAppImportVariantGroupTypes() {
434 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
435
436 archNames := make([]string, len(android.ArchTypeList()))
437 for i, archType := range android.ArchTypeList() {
438 archNames[i] = archType.Name
439 }
440 archVariantGroupType = createVariantGroupType(archNames, "Arch")
441}
442
443// Populates all variant struct properties at creation time.
444func (a *AndroidAppImport) populateAllVariantStructs() {
445 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
446 a.AddProperties(a.dpiVariants)
447
448 a.archVariants = reflect.New(archVariantGroupType).Interface()
449 a.AddProperties(a.archVariants)
450}
451
452func (a *AndroidAppImport) Privileged() bool {
453 return Bool(a.properties.Privileged)
454}
455
456func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
457 // android_app_import might have extra dependencies via uses_libs property.
458 // Don't track the dependency as we don't automatically add those libraries
459 // to the classpath. It should be explicitly added to java_libs property of APEX
460 return false
461}
462
Jiyong Park92315372021-04-02 08:45:46 +0900463func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
464 return android.SdkSpecPrivate
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800465}
466
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000467func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
468 return android.SdkSpecPrivate.ApiLevel
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800469}
470
Colin Cross8355c152021-08-10 19:24:07 -0700471func (a *AndroidAppImport) LintDepSets() LintDepSets {
472 return LintDepSets{}
473}
474
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800475var _ android.ApexModule = (*AndroidAppImport)(nil)
476
477// Implements android.ApexModule
478func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
479 sdkVersion android.ApiLevel) error {
480 // Do not check for prebuilts against the min_sdk_version of enclosing APEX
481 return nil
482}
483
484func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
485 props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
486
487 variantFields := make([]reflect.StructField, len(variants))
488 for i, variant := range variants {
489 variantFields[i] = reflect.StructField{
490 Name: proptools.FieldNameForProperty(variant),
491 Type: props,
492 }
493 }
494
495 variantGroupStruct := reflect.StructOf(variantFields)
496 return reflect.StructOf([]reflect.StructField{
497 {
498 Name: variantGroupName,
499 Type: variantGroupStruct,
500 },
501 })
502}
503
504// android_app_import imports a prebuilt apk with additional processing specified in the module.
505// DPI-specific apk source files can be specified using dpi_variants. Example:
506//
Colin Crossd079e0b2022-08-16 10:27:33 -0700507// android_app_import {
508// name: "example_import",
509// apk: "prebuilts/example.apk",
510// dpi_variants: {
511// mdpi: {
512// apk: "prebuilts/example_mdpi.apk",
513// },
514// xhdpi: {
515// apk: "prebuilts/example_xhdpi.apk",
516// },
517// },
518// presigned: true,
519// }
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800520func AndroidAppImportFactory() android.Module {
521 module := &AndroidAppImport{}
522 module.AddProperties(&module.properties)
523 module.AddProperties(&module.dexpreoptProperties)
524 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
525 module.populateAllVariantStructs()
526 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
527 module.processVariants(ctx)
528 })
529
530 android.InitApexModule(module)
531 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
532 android.InitDefaultableModule(module)
533 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
534
Ulya Trafimovich22890c42021-01-05 12:04:17 +0000535 module.usesLibrary.enforce = true
536
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800537 return module
538}
539
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800540type AndroidTestImport struct {
541 AndroidAppImport
542
Jiyong Park2f83b312022-10-20 20:18:35 +0900543 testProperties struct {
544 // list of compatibility suites (for example "cts", "vts") that the module should be
545 // installed into.
546 Test_suites []string `android:"arch_variant"`
547
548 // list of files or filegroup modules that provide data that should be installed alongside
549 // the test
550 Data []string `android:"path"`
551
552 // Install the test into a folder named for the module in all test suites.
553 Per_testcase_directory *bool
554 }
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800555
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800556 data android.Paths
557}
558
559func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800560 a.generateAndroidBuildActions(ctx)
561
562 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
563}
564
565func (a *AndroidTestImport) InstallInTestcases() bool {
566 return true
567}
568
569// android_test_import imports a prebuilt test apk with additional processing specified in the
570// module. DPI or arch variant configurations can be made as with android_app_import.
571func AndroidTestImportFactory() android.Module {
572 module := &AndroidTestImport{}
573 module.AddProperties(&module.properties)
574 module.AddProperties(&module.dexpreoptProperties)
575 module.AddProperties(&module.testProperties)
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800576 module.populateAllVariantStructs()
577 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
578 module.processVariants(ctx)
579 })
580
581 module.dexpreopter.isTest = true
582
583 android.InitApexModule(module)
584 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
585 android.InitDefaultableModule(module)
586 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
587
588 return module
589}