blob: f99b2991e802dd44350e7e6bb46ca5519b2c6b76 [file] [log] [blame]
Colin Cross30e076a2015-04-13 13:58:27 -07001// Copyright 2015 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 types for compiling Android apps.
18
19import (
Colin Cross43f08db2018-11-12 10:13:39 -080020 "path/filepath"
Colin Cross30e076a2015-04-13 13:58:27 -070021 "strings"
22
Colin Crossa4f08812018-10-02 22:03:40 -070023 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070024 "github.com/google/blueprint/proptools"
Colin Cross30e076a2015-04-13 13:58:27 -070025
Colin Cross635c3b02016-05-18 15:37:25 -070026 "android/soong/android"
Colin Crossa4f08812018-10-02 22:03:40 -070027 "android/soong/cc"
Colin Cross303e21f2018-08-07 16:49:25 -070028 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070029)
30
Colin Cross3bc7ffa2017-11-22 16:19:37 -080031func init() {
Colin Cross5ab4e6d2017-11-22 16:20:45 -080032 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Crossae5caf52018-05-22 11:11:52 -070033 android.RegisterModuleType("android_test", AndroidTestFactory)
Colin Cross252fc6f2018-10-04 15:22:03 -070034 android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
Colin Crossbd01e2a2018-10-04 15:21:03 -070035 android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
Colin Cross3bc7ffa2017-11-22 16:19:37 -080036}
37
Colin Cross30e076a2015-04-13 13:58:27 -070038// AndroidManifest.xml merging
39// package splits
40
Colin Crossfabb6082018-02-20 17:22:23 -080041type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -070042 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
43 // or an android_app_certificate module name in the form ":module".
Nan Zhangea568a42017-11-08 21:20:04 -080044 Certificate *string
Colin Cross7d5136f2015-05-11 13:39:40 -070045
Colin Crossbd01e2a2018-10-04 15:21:03 -070046 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -070047 Additional_certificates []string
48
49 // If set, create package-export.apk, which other packages can
50 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Nan Zhangea568a42017-11-08 21:20:04 -080051 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070052
Colin Cross16056062017-12-13 22:46:28 -080053 // Specifies that this app should be installed to the priv-app directory,
54 // where the system will grant it additional privileges not available to
55 // normal apps.
56 Privileged *bool
Colin Crossa97c5d32018-03-28 14:58:31 -070057
58 // list of resource labels to generate individual resource packages
59 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -040060
61 // Names of modules to be overridden. Listed modules can only be other binaries
62 // (in Make or Soong).
63 // This does not completely prevent installation of the overridden binaries, but if both
64 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
65 // from PRODUCT_PACKAGES.
66 Overrides []string
Colin Crossa4f08812018-10-02 22:03:40 -070067
68 // list of native libraries that will be provided in or alongside the resulting jar
69 Jni_libs []string `android:"arch_variant"`
70
Colin Cross43f08db2018-11-12 10:13:39 -080071 EmbedJNI bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -070072}
73
Colin Cross30e076a2015-04-13 13:58:27 -070074type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -070075 Library
76 aapt
77
Jiyong Parkc00cbd92018-10-30 21:20:05 +090078 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -070079
Colin Crossfabb6082018-02-20 17:22:23 -080080 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -070081
82 extraLinkFlags []string
Colin Crossa4f08812018-10-02 22:03:40 -070083
84 installJniLibs []jniLib
Colin Crossf6237212018-10-29 23:14:58 -070085
86 bundleFile android.Path
Colin Crosse1731a52017-12-14 11:22:55 -080087}
88
Colin Cross89c31582018-04-30 15:55:11 -070089func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
90 return nil
91}
92
Colin Cross66f78822018-05-02 12:58:28 -070093func (a *AndroidApp) ExportedStaticPackages() android.Paths {
94 return nil
95}
96
Colin Cross31656952018-05-24 16:11:20 -070097func (a *AndroidApp) ExportedManifest() android.Path {
98 return a.manifestPath
99}
100
Colin Crossa97c5d32018-03-28 14:58:31 -0700101var _ AndroidLibraryDependency = (*AndroidApp)(nil)
102
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900103type Certificate struct {
104 Pem, Key android.Path
Colin Cross30e076a2015-04-13 13:58:27 -0700105}
106
Colin Cross46c9b8b2017-06-22 16:51:17 -0700107func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
108 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700109
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800110 if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700111 a.aapt.deps(ctx, sdkContext(a))
Colin Cross30e076a2015-04-13 13:58:27 -0700112 }
Colin Crossa4f08812018-10-02 22:03:40 -0700113
114 for _, jniTarget := range ctx.MultiTargets() {
115 variation := []blueprint.Variation{
116 {Mutator: "arch", Variation: jniTarget.String()},
117 {Mutator: "link", Variation: "shared"},
118 }
119 tag := &jniDependencyTag{
120 target: jniTarget,
121 }
122 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
123 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700124
125 cert := android.SrcIsModule(String(a.appProperties.Certificate))
126 if cert != "" {
127 ctx.AddDependency(ctx.Module(), certificateTag, cert)
128 }
129
130 for _, cert := range a.appProperties.Additional_certificates {
131 cert = android.SrcIsModule(cert)
132 if cert != "" {
133 ctx.AddDependency(ctx.Module(), certificateTag, cert)
134 } else {
135 ctx.PropertyErrorf("additional_certificates",
136 `must be names of android_app_certificate modules in the form ":module"`)
137 }
138 }
Colin Cross30e076a2015-04-13 13:58:27 -0700139}
140
Colin Cross46c9b8b2017-06-22 16:51:17 -0700141func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700142 a.generateAndroidBuildActions(ctx)
143}
144
Colin Cross43f08db2018-11-12 10:13:39 -0800145// Returns whether this module should have the dex file stored uncompressed in the APK.
146func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
Colin Cross5a0dcd52018-10-05 14:20:06 -0700147 if ctx.Config().UnbundledBuild() {
Colin Cross43f08db2018-11-12 10:13:39 -0800148 return false
Colin Cross5a0dcd52018-10-05 14:20:06 -0700149 }
150
Colin Cross5a0dcd52018-10-05 14:20:06 -0700151 // Uncompress dex in APKs of privileged apps, and modules used by privileged apps.
Colin Cross43f08db2018-11-12 10:13:39 -0800152 return ctx.Config().UncompressPrivAppDex() &&
Colin Cross5a0dcd52018-10-05 14:20:06 -0700153 (Bool(a.appProperties.Privileged) ||
Colin Cross43f08db2018-11-12 10:13:39 -0800154 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()))
Colin Cross5a0dcd52018-10-05 14:20:06 -0700155}
156
Colin Crossae5caf52018-05-22 11:11:52 -0700157func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
158 linkFlags := append([]string(nil), a.extraLinkFlags...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800159
Colin Crosse78dcd32018-04-19 15:25:19 -0700160 hasProduct := false
161 for _, f := range a.aaptProperties.Aaptflags {
162 if strings.HasPrefix(f, "--product") {
163 hasProduct = true
164 }
165 }
166
167 // Product characteristics
168 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
169 linkFlags = append(linkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
170 }
171
Dan Willemsen72be5902018-10-24 20:24:57 -0700172 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
173 // Product AAPT config
174 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
175 linkFlags = append(linkFlags, "-c", aaptConfig)
176 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700177
Dan Willemsen72be5902018-10-24 20:24:57 -0700178 // Product AAPT preferred config
179 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
180 linkFlags = append(linkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
181 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700182 }
183
Colin Crossa97c5d32018-03-28 14:58:31 -0700184 // TODO: LOCAL_PACKAGE_OVERRIDES
185 // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800186
Colin Cross83bb3162018-06-25 15:48:06 -0700187 a.aapt.buildActions(ctx, sdkContext(a), linkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700188
Colin Cross46c9b8b2017-06-22 16:51:17 -0700189 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700190 a.properties.Manifest = nil
Colin Cross30e076a2015-04-13 13:58:27 -0700191
Colin Cross89c31582018-04-30 15:55:11 -0700192 var staticLibProguardFlagFiles android.Paths
193 ctx.VisitDirectDeps(func(m android.Module) {
194 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
195 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
196 }
197 })
198
199 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
200
201 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
202 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800203
Colin Cross43f08db2018-11-12 10:13:39 -0800204 a.deviceProperties.UncompressDex = a.shouldUncompressDex(ctx)
205
206 var installDir string
207 if ctx.ModuleName() == "framework-res" {
208 // framework-res.apk is installed as system/framework/framework-res.apk
209 installDir = "framework"
210 } else if Bool(a.appProperties.Privileged) {
211 installDir = filepath.Join("priv-app", ctx.ModuleName())
212 } else {
213 installDir = filepath.Join("app", ctx.ModuleName())
214 }
215 a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, ctx.ModuleName()+".apk")
Colin Cross5a0dcd52018-10-05 14:20:06 -0700216
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800217 if ctx.ModuleName() != "framework-res" {
218 a.Module.compile(ctx, a.aaptSrcJar)
219 }
Colin Cross30e076a2015-04-13 13:58:27 -0700220
Colin Cross43f08db2018-11-12 10:13:39 -0800221 dexJarFile := a.maybeStrippedDexJarFile
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800222
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900223 var certificates []Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700224
Colin Crossa4f08812018-10-02 22:03:40 -0700225 var jniJarFile android.WritablePath
Colin Crossbd01e2a2018-10-04 15:21:03 -0700226 jniLibs, certificateDeps := a.collectAppDeps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700227 if len(jniLibs) > 0 {
228 embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI
229 if embedJni {
230 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
231 TransformJniLibsToJar(ctx, jniJarFile, jniLibs)
232 } else {
233 a.installJniLibs = jniLibs
234 }
235 }
236
Colin Crossbd01e2a2018-10-04 15:21:03 -0700237 if ctx.Failed() {
238 return
239 }
240
241 cert := String(a.appProperties.Certificate)
242 certModule := android.SrcIsModule(cert)
243 if certModule != "" {
244 a.certificate = certificateDeps[0]
245 certificateDeps = certificateDeps[1:]
246 } else if cert != "" {
247 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900248 a.certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700249 defaultDir.Join(ctx, cert+".x509.pem"),
250 defaultDir.Join(ctx, cert+".pk8"),
251 }
252 } else {
253 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900254 a.certificate = Certificate{pem, key}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700255 }
256
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900257 certificates = append([]Certificate{a.certificate}, certificateDeps...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700258
Colin Cross5a0dcd52018-10-05 14:20:06 -0700259 packageFile := android.PathForModuleOut(ctx, "package.apk")
260 CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800261 a.outputFile = packageFile
262
Colin Crossf6237212018-10-29 23:14:58 -0700263 bundleFile := android.PathForModuleOut(ctx, "base.zip")
264 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
265 a.bundleFile = bundleFile
266
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800267 if ctx.ModuleName() == "framework-res" {
268 // framework-res.apk is installed as system/framework/framework-res.apk
269 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross16056062017-12-13 22:46:28 -0800270 } else if Bool(a.appProperties.Privileged) {
Colin Cross43f08db2018-11-12 10:13:39 -0800271 ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800272 } else {
Colin Cross43f08db2018-11-12 10:13:39 -0800273 ctx.InstallFile(android.PathForModuleInstall(ctx, "app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800274 }
Colin Cross30e076a2015-04-13 13:58:27 -0700275}
276
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900277func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) {
Colin Crossa4f08812018-10-02 22:03:40 -0700278 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900279 var certificates []Certificate
Colin Crossa4f08812018-10-02 22:03:40 -0700280
281 ctx.VisitDirectDeps(func(module android.Module) {
282 otherName := ctx.OtherModuleName(module)
283 tag := ctx.OtherModuleDependencyTag(module)
284
285 if jniTag, ok := tag.(*jniDependencyTag); ok {
286 if dep, ok := module.(*cc.Module); ok {
287 lib := dep.OutputFile()
288 if lib.Valid() {
289 jniLibs = append(jniLibs, jniLib{
290 name: ctx.OtherModuleName(module),
291 path: lib.Path(),
292 target: jniTag.target,
293 })
294 } else {
295 ctx.ModuleErrorf("dependency %q missing output file", otherName)
296 }
297 } else {
298 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
299
300 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700301 } else if tag == certificateTag {
302 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900303 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700304 } else {
305 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
306 }
Colin Crossa4f08812018-10-02 22:03:40 -0700307 }
308 })
309
Colin Crossbd01e2a2018-10-04 15:21:03 -0700310 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700311}
312
Colin Cross36242852017-06-23 15:06:31 -0700313func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700314 module := &AndroidApp{}
315
Colin Cross66dbc0b2017-12-28 12:23:20 -0800316 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
317 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
318
Colin Crossae5caf52018-05-22 11:11:52 -0700319 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700320 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossae5caf52018-05-22 11:11:52 -0700321
Colin Cross36242852017-06-23 15:06:31 -0700322 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700323 &module.Module.properties,
324 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800325 &module.Module.dexpreoptProperties,
Colin Crossa97c5d32018-03-28 14:58:31 -0700326 &module.Module.protoProperties,
327 &module.aaptProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700328 &module.appProperties)
Colin Cross36242852017-06-23 15:06:31 -0700329
Colin Crossa9d8bee2018-10-02 13:59:46 -0700330 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
331 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
332 })
333
Colin Crossa4f08812018-10-02 22:03:40 -0700334 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
335 android.InitDefaultableModule(module)
336
Colin Cross36242852017-06-23 15:06:31 -0700337 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700338}
Colin Crossae5caf52018-05-22 11:11:52 -0700339
340type appTestProperties struct {
341 Instrumentation_for *string
342}
343
344type AndroidTest struct {
345 AndroidApp
346
347 appTestProperties appTestProperties
348
349 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -0700350
351 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -0700352 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -0700353}
354
355func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700356 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -0700357
Jack He33338892018-09-19 02:21:28 -0700358 a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath)
Colin Crossd96ca352018-08-10 16:06:24 -0700359 a.data = ctx.ExpandSources(a.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -0700360}
361
362func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
363 android.ExtractSourceDeps(ctx, a.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -0700364 android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -0700365 android.ExtractSourcesDeps(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -0700366 a.AndroidApp.DepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -0700367 if a.appTestProperties.Instrumentation_for != nil {
368 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
369 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
370 // use instrumentationForTag instead of libTag.
371 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
372 }
Colin Crossae5caf52018-05-22 11:11:52 -0700373}
374
375func AndroidTestFactory() android.Module {
376 module := &AndroidTest{}
377
378 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
Colin Cross5067db92018-09-17 16:46:35 -0700379
380 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700381 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossa4f08812018-10-02 22:03:40 -0700382 module.appProperties.EmbedJNI = true
Colin Cross43f08db2018-11-12 10:13:39 -0800383 module.Module.dexpreopter.isTest = true
Colin Crossae5caf52018-05-22 11:11:52 -0700384
385 module.AddProperties(
386 &module.Module.properties,
387 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800388 &module.Module.dexpreoptProperties,
Colin Crossae5caf52018-05-22 11:11:52 -0700389 &module.Module.protoProperties,
390 &module.aaptProperties,
391 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -0700392 &module.appTestProperties,
393 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -0700394
Colin Crossa4f08812018-10-02 22:03:40 -0700395 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
396 android.InitDefaultableModule(module)
Colin Crossae5caf52018-05-22 11:11:52 -0700397 return module
398}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700399
Colin Cross252fc6f2018-10-04 15:22:03 -0700400type appTestHelperAppProperties struct {
401 // list of compatibility suites (for example "cts", "vts") that the module should be
402 // installed into.
403 Test_suites []string `android:"arch_variant"`
404}
405
406type AndroidTestHelperApp struct {
407 AndroidApp
408
409 appTestHelperAppProperties appTestHelperAppProperties
410}
411
412func AndroidTestHelperAppFactory() android.Module {
413 module := &AndroidTestHelperApp{}
414
415 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
416
417 module.Module.properties.Installable = proptools.BoolPtr(true)
418 module.appProperties.EmbedJNI = true
Colin Cross43f08db2018-11-12 10:13:39 -0800419 module.Module.dexpreopter.isTest = true
Colin Cross252fc6f2018-10-04 15:22:03 -0700420
421 module.AddProperties(
422 &module.Module.properties,
423 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800424 &module.Module.dexpreoptProperties,
Colin Cross252fc6f2018-10-04 15:22:03 -0700425 &module.Module.protoProperties,
426 &module.aaptProperties,
427 &module.appProperties,
428 &module.appTestHelperAppProperties)
429
430 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
431 android.InitDefaultableModule(module)
432 return module
433}
434
Colin Crossbd01e2a2018-10-04 15:21:03 -0700435type AndroidAppCertificate struct {
436 android.ModuleBase
437 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900438 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700439}
440
441type AndroidAppCertificateProperties struct {
442 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
443 Certificate *string
444}
445
446func AndroidAppCertificateFactory() android.Module {
447 module := &AndroidAppCertificate{}
448 module.AddProperties(&module.properties)
449 android.InitAndroidModule(module)
450 return module
451}
452
453func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) {
454}
455
456func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
457 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900458 c.Certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700459 android.PathForModuleSrc(ctx, cert+".x509.pem"),
460 android.PathForModuleSrc(ctx, cert+".pk8"),
461 }
462}