blob: ce323ca4df469624b0666062613e3dd8eb0cc21c [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
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 apex
16
17import (
18 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090019 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090020 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "strings"
22
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080024 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070026
27 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080028 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070029 "android/soong/cc"
30 prebuilt_etc "android/soong/etc"
31 "android/soong/java"
32 "android/soong/python"
33 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034)
35
Jiyong Park8e6d52f2020-11-19 14:37:47 +090036func init() {
37 android.RegisterModuleType("apex", BundleFactory)
38 android.RegisterModuleType("apex_test", testApexBundleFactory)
39 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
40 android.RegisterModuleType("apex_defaults", defaultsFactory)
41 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
42 android.RegisterModuleType("override_apex", overrideApexFactory)
43 android.RegisterModuleType("apex_set", apexSetFactory)
44
45 android.PreDepsMutators(RegisterPreDepsMutators)
46 android.PostDepsMutators(RegisterPostDepsMutators)
47}
48
49func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
51 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
52}
53
54func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
55 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
56 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
57 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
58 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
59 ctx.BottomUp("apex", apexMutator).Parallel()
60 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
61 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
62 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
63}
64
65type apexBundleProperties struct {
66 // Json manifest file describing meta info of this APEX bundle. Default:
67 // "apex_manifest.json"
68 Manifest *string `android:"path"`
69
70 // AndroidManifest.xml file used for the zip container of this APEX bundle.
71 // If unspecified, a default one is automatically generated.
72 AndroidManifest *string `android:"path"`
73
74 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
75 // device (/apex/<apex_name>).
76 // If unspecified, defaults to the value of name.
77 Apex_name *string
78
79 // Determines the file contexts file for setting security context to each file in this APEX bundle.
80 // For platform APEXes, this should points to a file under /system/sepolicy
81 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
82 File_contexts *string `android:"path"`
83
84 ApexNativeDependencies
85
86 // List of java libraries that are embedded inside this APEX bundle
87 Java_libs []string
88
89 // List of prebuilt files that are embedded inside this APEX bundle
90 Prebuilts []string
91
92 // List of BPF programs inside APEX
93 Bpfs []string
94
95 // Name of the apex_key module that provides the private key to sign APEX
96 Key *string
97
98 // The type of APEX to build. Controls what the APEX payload is. Either
99 // 'image', 'zip' or 'both'. Default: 'image'.
100 Payload_type *string
101
102 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
103 // or an android_app_certificate module name in the form ":module".
104 Certificate *string
105
106 // Whether this APEX is installable to one of the partitions. Default: true.
107 Installable *bool
108
109 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
110 // Default is false.
111 Use_vendor *bool
112
113 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
114 Ignore_system_library_special_case *bool
115
116 Multilib apexMultilibProperties
117
118 // List of sanitizer names that this APEX is enabled for
119 SanitizerNames []string `blueprint:"mutated"`
120
121 PreventInstall bool `blueprint:"mutated"`
122
123 HideFromMake bool `blueprint:"mutated"`
124
125 // package format of this apex variant; could be non-flattened, flattened, or zip.
126 // imageApex, zipApex or flattened
127 ApexType apexPackaging `blueprint:"mutated"`
128
129 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
130 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
131 // is implied. This value affects all modules included in this APEX. In other words, they are
132 // also built with the SDKs specified here.
133 Uses_sdks []string
134
135 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
136 // Should be only used in tests#.
137 Test_only_no_hashtree *bool
138
139 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
140 // Should be only used in tests#.
141 Test_only_unsigned_payload *bool
142
143 IsCoverageVariant bool `blueprint:"mutated"`
144
145 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
146 // rules for making sure that the APEX is truly updatable.
147 // - To be updatable, min_sdk_version should be set as well
148 // This will also disable the size optimizations like symlinking to the system libs.
149 // Default is false.
150 Updatable *bool
151
152 // The minimum SDK version that this apex must be compatibile with.
153 Min_sdk_version *string
154
155 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
156 // Should be only used in non-system apexes (e.g. vendor: true).
157 // Default is false.
158 Use_vndk_as_stable *bool
159
160 // The type of filesystem to use for an image apex. Either 'ext4' or 'f2fs'.
161 // Default 'ext4'.
162 Payload_fs_type *string
163}
164
165type ApexNativeDependencies struct {
166 // List of native libraries
167 Native_shared_libs []string
168
169 // List of JNI libraries
170 Jni_libs []string
171
172 // List of native executables
173 Binaries []string
174
175 // List of native tests
176 Tests []string
177}
178
179type apexMultilibProperties struct {
180 // Native dependencies whose compile_multilib is "first"
181 First ApexNativeDependencies
182
183 // Native dependencies whose compile_multilib is "both"
184 Both ApexNativeDependencies
185
186 // Native dependencies whose compile_multilib is "prefer32"
187 Prefer32 ApexNativeDependencies
188
189 // Native dependencies whose compile_multilib is "32"
190 Lib32 ApexNativeDependencies
191
192 // Native dependencies whose compile_multilib is "64"
193 Lib64 ApexNativeDependencies
194}
195
196type apexTargetBundleProperties struct {
197 Target struct {
198 // Multilib properties only for android.
199 Android struct {
200 Multilib apexMultilibProperties
201 }
202
203 // Multilib properties only for host.
204 Host struct {
205 Multilib apexMultilibProperties
206 }
207
208 // Multilib properties only for host linux_bionic.
209 Linux_bionic struct {
210 Multilib apexMultilibProperties
211 }
212
213 // Multilib properties only for host linux_glibc.
214 Linux_glibc struct {
215 Multilib apexMultilibProperties
216 }
217 }
218}
219
220type overridableProperties struct {
221 // List of APKs to package inside APEX
222 Apps []string
223
224 // List of runtime resource overlays (RROs) inside APEX
225 Rros []string
226
227 // Names of modules to be overridden. Listed modules can only be other binaries
228 // (in Make or Soong).
229 // This does not completely prevent installation of the overridden binaries, but if both
230 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
231 // from PRODUCT_PACKAGES.
232 Overrides []string
233
234 // Logging Parent value
235 Logging_parent string
236
237 // Apex Container Package Name.
238 // Override value for attribute package:name in AndroidManifest.xml
239 Package_name string
240
241 // A txt file containing list of files that are allowed to be included in this APEX.
242 Allowed_files *string `android:"path"`
243}
244
245type apexBundle struct {
246 android.ModuleBase
247 android.DefaultableModuleBase
248 android.OverridableModuleBase
249 android.SdkBase
250
251 properties apexBundleProperties
252 targetProperties apexTargetBundleProperties
253 overridableProperties overridableProperties
254
255 // specific to apex_vndk modules
256 vndkProperties apexVndkProperties
257
258 bundleModuleFile android.WritablePath
259 outputFile android.WritablePath
260 installDir android.InstallPath
261
262 prebuiltFileToDelete string
263
264 public_key_file android.Path
265 private_key_file android.Path
266
267 container_certificate_file android.Path
268 container_private_key_file android.Path
269
270 fileContexts android.WritablePath
271
272 // list of files to be included in this apex
273 filesInfo []apexFile
274
275 // list of module names that should be installed along with this APEX
276 requiredDeps []string
277
278 // list of module names that this APEX is including (to be shown via *-deps-info target)
279 android.ApexBundleDepsInfo
280
281 testApex bool
282 vndkApex bool
283 artApex bool
284 primaryApexType bool
285
286 manifestJsonOut android.WritablePath
287 manifestPbOut android.WritablePath
288
289 // list of commands to create symlinks for backward compatibility.
290 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
291 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
292 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
293 compatSymlinks []string
294
295 // Suffix of module name in Android.mk
296 // ".flattened", ".apex", ".zipapex", or ""
297 suffix string
298
299 installedFilesFile android.WritablePath
300
301 // Whether to create symlink to the system file instead of having a file
302 // inside the apex or not
303 linkToSystemLib bool
304
305 // Struct holding the merged notice file paths in different formats
306 mergedNotices android.NoticeOutputs
307
308 // Optional list of lint report zip files for apexes that contain java or app modules
309 lintReports android.Paths
310
311 payloadFsType fsType
312
313 distFiles android.TaggedDistFiles
314}
315
316type apexFileClass int
317
Jooyung Han72bd2f82019-10-23 16:46:38 +0900318const (
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900319 etc apexFileClass = iota
320 nativeSharedLib
321 nativeExecutable
322 shBinary
323 pyBinary
324 goBinary
325 javaSharedLib
326 nativeTest
327 app
328 appSet
Jooyung Han72bd2f82019-10-23 16:46:38 +0900329)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900330
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900331func (class apexFileClass) NameInMake() string {
332 switch class {
333 case etc:
334 return "ETC"
335 case nativeSharedLib:
336 return "SHARED_LIBRARIES"
337 case nativeExecutable, shBinary, pyBinary, goBinary:
338 return "EXECUTABLES"
339 case javaSharedLib:
340 return "JAVA_LIBRARIES"
341 case nativeTest:
342 return "NATIVE_TESTS"
343 case app, appSet:
344 // b/142537672 Why isn't this APP? We want to have full control over
345 // the paths and file names of the apk file under the flattend APEX.
346 // If this is set to APP, then the paths and file names are modified
347 // by the Make build system. For example, it is installed to
348 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
349 // /system/apex/<apexname>/app/<Appname> because the build system automatically
350 // appends module name (which is <apexname>.<Appname> to the path.
351 return "ETC"
352 default:
353 panic(fmt.Errorf("unknown class %d", class))
354 }
355}
356
357// apexFile represents a file in an APEX bundle
358type apexFile struct {
359 builtFile android.Path
360 stem string
361 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
362 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
363 androidMkModuleName string
364 installDir string
365 class apexFileClass
366 module android.Module
367 // list of symlinks that will be created in installDir that point to this apexFile
368 symlinks []string
369 dataPaths []android.DataPath
370 transitiveDep bool
371 moduleDir string
372
373 requiredModuleNames []string
374 targetRequiredModuleNames []string
375 hostRequiredModuleNames []string
376
377 jacocoReportClassesFile android.Path // only for javalibs and apps
378 lintDepSets java.LintDepSets // only for javalibs and apps
379 certificate java.Certificate // only for apps
380 overriddenPackageName string // only for apps
381
382 isJniLib bool
383
384 noticeFiles android.Paths
385}
386
387func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
388 ret := apexFile{
389 builtFile: builtFile,
390 androidMkModuleName: androidMkModuleName,
391 installDir: installDir,
392 class: class,
393 module: module,
394 }
395 if module != nil {
396 ret.moduleDir = ctx.OtherModuleDir(module)
397 ret.requiredModuleNames = module.RequiredModuleNames()
398 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
399 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
400 ret.noticeFiles = module.NoticeFiles()
401 }
402 return ret
403}
404
405func (af *apexFile) Ok() bool {
406 return af.builtFile != nil && af.builtFile.String() != ""
407}
408
409func (af *apexFile) apexRelativePath(path string) string {
410 return filepath.Join(af.installDir, path)
411}
412
413// Path() returns path of this apex file relative to the APEX root
414func (af *apexFile) Path() string {
415 return af.apexRelativePath(af.Stem())
416}
417
418func (af *apexFile) Stem() string {
419 if af.stem != "" {
420 return af.stem
421 }
422 return af.builtFile.Base()
423}
424
425// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
426func (af *apexFile) SymlinkPaths() []string {
427 var ret []string
428 for _, symlink := range af.symlinks {
429 ret = append(ret, af.apexRelativePath(symlink))
430 }
431 return ret
432}
433
434func (af *apexFile) AvailableToPlatform() bool {
435 if af.module == nil {
436 return false
437 }
438 if am, ok := af.module.(android.ApexModule); ok {
439 return am.AvailableFor(android.AvailableToPlatform)
440 }
441 return false
442}
443
444func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
445 nativeModules ApexNativeDependencies,
446 target android.Target, imageVariation string) {
447 // Use *FarVariation* to be able to depend on modules having
448 // conflicting variations with this module. This is required since
449 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
450 // for native shared libs.
451
452 binVariations := target.Variations()
453 libVariations := append(target.Variations(),
454 blueprint.Variation{Mutator: "link", Variation: "shared"})
455
456 if ctx.Device() {
457 binVariations = append(binVariations,
458 blueprint.Variation{Mutator: "image", Variation: imageVariation})
459 libVariations = append(libVariations,
460 blueprint.Variation{Mutator: "image", Variation: imageVariation},
461 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
462 }
463
464 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
465
466 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
467
468 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
469
470 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
471}
472
473func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
474 if ctx.Os().Class == android.Device {
475 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
476 } else {
477 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
478 if ctx.Os().Bionic() {
479 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
480 } else {
481 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
482 }
483 }
484}
485
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900486type dependencyTag struct {
487 blueprint.BaseDependencyTag
488 name string
Jiyong Park0f80c182020-01-31 02:49:53 +0900489
490 // determines if the dependent will be part of the APEX payload
491 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900492}
493
494var (
Jiyong Park0f80c182020-01-31 02:49:53 +0900495 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +0900496 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +0900497 executableTag = dependencyTag{name: "executable", payload: true}
498 javaLibTag = dependencyTag{name: "javaLib", payload: true}
499 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
500 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900501 keyTag = dependencyTag{name: "key"}
502 certificateTag = dependencyTag{name: "certificate"}
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +0900504 rroTag = dependencyTag{name: "rro", payload: true}
markchien2f59ec92020-09-02 16:23:38 +0800505 bpfTag = dependencyTag{name: "bpf", payload: true}
Colin Cross56a83212020-09-15 18:30:11 -0700506 testForTag = dependencyTag{name: "test for"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900507)
508
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900509func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
510 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
511 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
512 }
513
514 targets := ctx.MultiTargets()
515 config := ctx.DeviceConfig()
516 imageVariation := a.getImageVariation(ctx)
517
518 a.combineProperties(ctx)
519
520 has32BitTarget := false
521 for _, target := range targets {
522 if target.Arch.ArchType.Multilib == "lib32" {
523 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000524 }
525 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 for i, target := range targets {
527 if target.HostCross {
528 // Don't include artifats for the host cross targets because there is no way
529 // for us to run those artifacts natively on host
530 continue
531 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000532
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900533 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
534 // multilib.both
535 addDependenciesForNativeModules(ctx,
536 ApexNativeDependencies{
537 Native_shared_libs: a.properties.Native_shared_libs,
538 Tests: a.properties.Tests,
539 Jni_libs: a.properties.Jni_libs,
540 Binaries: nil,
541 },
542 target, imageVariation)
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000543
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900544 // Add native modules targetting both ABIs
545 addDependenciesForNativeModules(ctx,
546 a.properties.Multilib.Both,
547 target,
548 imageVariation)
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900549
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900550 isPrimaryAbi := i == 0
551 if isPrimaryAbi {
552 // When multilib.* is omitted for binaries, it implies
553 // multilib.first
554 addDependenciesForNativeModules(ctx,
555 ApexNativeDependencies{
556 Native_shared_libs: nil,
557 Tests: nil,
558 Jni_libs: nil,
559 Binaries: a.properties.Binaries,
560 },
561 target, imageVariation)
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000562
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900563 // Add native modules targetting the first ABI
564 addDependenciesForNativeModules(ctx,
565 a.properties.Multilib.First,
566 target,
567 imageVariation)
568 }
569
570 switch target.Arch.ArchType.Multilib {
571 case "lib32":
572 // Add native modules targetting 32-bit ABI
573 addDependenciesForNativeModules(ctx,
574 a.properties.Multilib.Lib32,
575 target,
576 imageVariation)
577
578 addDependenciesForNativeModules(ctx,
579 a.properties.Multilib.Prefer32,
580 target,
581 imageVariation)
582 case "lib64":
583 // Add native modules targetting 64-bit ABI
584 addDependenciesForNativeModules(ctx,
585 a.properties.Multilib.Lib64,
586 target,
587 imageVariation)
588
589 if !has32BitTarget {
590 addDependenciesForNativeModules(ctx,
591 a.properties.Multilib.Prefer32,
592 target,
593 imageVariation)
594 }
595 }
596 }
597
598 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
599 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
600 // b/144532908
601 archForPrebuiltEtc := config.Arches()[0]
602 for _, arch := range config.Arches() {
603 // Prefer 64-bit arch if there is any
604 if arch.ArchType.Multilib == "lib64" {
605 archForPrebuiltEtc = arch
606 break
607 }
608 }
609 ctx.AddFarVariationDependencies([]blueprint.Variation{
610 {Mutator: "os", Variation: ctx.Os().String()},
611 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
612 }, prebuiltTag, a.properties.Prebuilts...)
613
614 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
615 javaLibTag, a.properties.Java_libs...)
616
617 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
618 bpfTag, a.properties.Bpfs...)
619
620 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
621 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
622 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
623 javaLibTag, "jacocoagent")
624 }
625
626 if String(a.properties.Key) == "" {
627 ctx.ModuleErrorf("key is missing")
628 return
629 }
630 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
631
632 cert := android.SrcIsModule(a.getCertString(ctx))
633 if cert != "" {
634 ctx.AddDependency(ctx.Module(), certificateTag, cert)
635 }
636
637 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
638 if len(a.properties.Uses_sdks) > 0 {
639 sdkRefs := []android.SdkRef{}
640 for _, str := range a.properties.Uses_sdks {
641 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
642 sdkRefs = append(sdkRefs, parsed)
643 }
644 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100645 }
646}
647
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900648func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
649 if a.overridableProperties.Allowed_files != nil {
650 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100651 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
653 androidAppTag, a.overridableProperties.Apps...)
654 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
655 rroTag, a.overridableProperties.Rros...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100656}
657
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900658type ApexBundleInfo struct {
659 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100660}
661
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900662var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900663
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900664// Mark the direct and transitive dependencies of apex bundles so that they
665// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900666func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900667 if !mctx.Module().Enabled() {
668 return
669 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900670 a, ok := mctx.Module().(*apexBundle)
671 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900672 return
673 }
Jooyung Handf78e212020-07-22 15:54:47 +0900674
675 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
676 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
677 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
678 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
679 return
680 }
681
Colin Cross56a83212020-09-15 18:30:11 -0700682 contents := make(map[string]android.ApexMembership)
683
684 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900685 am, ok := child.(android.ApexModule)
686 if !ok || !am.CanHaveApexVariants() {
687 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900688 }
Paul Duffina37eca22020-07-22 13:00:54 +0100689 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900690 return false
691 }
Jooyung Handf78e212020-07-22 15:54:47 +0900692 if excludeVndkLibs {
693 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
694 return false
695 }
696 }
Colin Cross56a83212020-09-15 18:30:11 -0700697 return true
698 }
699
700 mctx.WalkDeps(func(child, parent android.Module) bool {
701 if !continueApexDepsWalk(child, parent) {
702 return false
703 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900704
705 depName := mctx.OtherModuleName(child)
706 // If the parent is apexBundle, this child is directly depended.
707 _, directDep := parent.(*apexBundle)
Colin Cross56a83212020-09-15 18:30:11 -0700708 contents[depName] = contents[depName].Add(directDep)
709 return true
710 })
711
712 apexContents := android.NewApexContents(mctx.ModuleName(), contents)
713 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
714 Contents: apexContents,
715 })
716
717 apexInfo := android.ApexInfo{
718 ApexVariationName: mctx.ModuleName(),
719 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
720 RequiredSdks: a.RequiredSdks(),
721 Updatable: a.Updatable(),
722 InApexes: []string{mctx.ModuleName()},
723 ApexContents: []*android.ApexContents{apexContents},
724 }
725
726 mctx.WalkDeps(func(child, parent android.Module) bool {
727 if !continueApexDepsWalk(child, parent) {
728 return false
729 }
730
731 child.(android.ApexModule).BuildForApex(apexInfo)
Jooyung Han698dd9f2020-07-22 15:17:19 +0900732 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900733 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900734}
735
Colin Crossaede88c2020-08-11 12:17:01 -0700736func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
737 if !mctx.Module().Enabled() {
738 return
739 }
740 if am, ok := mctx.Module().(android.ApexModule); ok {
741 // Check if any dependencies use unique apex variations. If so, use unique apex variations
742 // for this module.
Colin Cross56a83212020-09-15 18:30:11 -0700743 android.UpdateUniqueApexVariationsForDeps(mctx, am)
744 }
745}
746
747func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
748 if !mctx.Module().Enabled() {
749 return
750 }
751 // Check if this module is a test for an apex. If so, add a dependency on the apex
752 // in order to retrieve its contents later.
753 if am, ok := mctx.Module().(android.ApexModule); ok {
754 if testFor := am.TestFor(); len(testFor) > 0 {
755 mctx.AddFarVariationDependencies([]blueprint.Variation{
756 {Mutator: "os", Variation: am.Target().OsVariation()},
757 {"arch", "common"},
758 }, testForTag, testFor...)
759 }
760 }
761}
762
763func apexTestForMutator(mctx android.BottomUpMutatorContext) {
764 if !mctx.Module().Enabled() {
765 return
766 }
767
768 if _, ok := mctx.Module().(android.ApexModule); ok {
769 var contents []*android.ApexContents
770 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
771 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
772 contents = append(contents, abInfo.Contents)
773 }
774 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
775 ApexContents: contents,
776 })
Colin Crossaede88c2020-08-11 12:17:01 -0700777 }
778}
779
Jiyong Park89e850a2020-04-07 16:37:39 +0900780// mark if a module cannot be available to platform. A module cannot be available
781// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
782// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
783func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
784 // Host and recovery are not considered as platform
785 if mctx.Host() || mctx.Module().InstallInRecovery() {
786 return
787 }
788
789 if am, ok := mctx.Module().(android.ApexModule); ok {
790 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
791
Jiyong Park89e850a2020-04-07 16:37:39 +0900792 // If any of the dep is not available to platform, this module is also considered
793 // as being not available to platform even if it has "//apex_available:platform"
794 mctx.VisitDirectDeps(func(child android.Module) {
795 if !am.DepIsInSameApex(mctx, child) {
796 // if the dependency crosses apex boundary, don't consider it
797 return
798 }
799 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
800 availableToPlatform = false
801 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
802 }
803 })
804
805 // Exception 1: stub libraries and native bridge libraries are always available to platform
806 if cc, ok := mctx.Module().(*cc.Module); ok &&
807 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
808 availableToPlatform = true
809 }
810
811 // Exception 2: bootstrap bionic libraries are also always available to platform
812 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
813 availableToPlatform = true
814 }
815
816 if !availableToPlatform {
817 am.SetNotAvailableForPlatform()
818 }
819 }
820}
821
Paul Duffin65347702020-03-31 15:23:40 +0100822// If a module in an APEX depends on a module from an SDK then it needs an APEX
823// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
824func inAnySdk(module android.Module) bool {
825 if sa, ok := module.(android.SdkAware); ok {
826 return sa.IsInAnySdk()
827 }
828
829 return false
830}
831
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900832// Create apex variations if a module is included in APEX(s).
833func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900834 if !mctx.Module().Enabled() {
835 return
836 }
Colin Cross56a83212020-09-15 18:30:11 -0700837
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900838 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700839 android.CreateApexVariations(mctx, am)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000840 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900841 // apex bundle itself is mutated so that it and its modules have same
842 // apex variant.
843 apexBundleName := mctx.ModuleName()
844 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900845 } else if o, ok := mctx.Module().(*OverrideApex); ok {
846 apexBundleName := o.GetOverriddenModuleName()
847 if apexBundleName == "" {
848 mctx.ModuleErrorf("base property is not set")
849 return
850 }
851 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900852 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900853
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854}
Sundong Ahne9b55722019-09-06 17:37:42 +0900855
Colin Cross56a83212020-09-15 18:30:11 -0700856func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
857 if !mctx.Module().Enabled() {
858 return
859 }
860 if am, ok := mctx.Module().(android.ApexModule); ok {
861 android.UpdateDirectlyInAnyApex(mctx, am)
862 }
863}
864
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900865type apexPackaging int
866
867const (
868 imageApex apexPackaging = iota
869 zipApex
870 flattenedApex
871)
872
873const (
874 imageApexSuffix = ".apex"
875 zipApexSuffix = ".zipapex"
876 flattenedSuffix = ".flattened"
877
878 imageApexType = "image"
879 zipApexType = "zip"
880 flattenedApexType = "flattened"
881
882 ext4FsType = "ext4"
883 f2fsFsType = "f2fs"
884)
885
886// The suffix for the output "file", not the module
887func (a apexPackaging) suffix() string {
888 switch a {
889 case imageApex:
890 return imageApexSuffix
891 case zipApex:
892 return zipApexSuffix
893 default:
894 panic(fmt.Errorf("unknown APEX type %d", a))
895 }
896}
897
898func (a apexPackaging) name() string {
899 switch a {
900 case imageApex:
901 return imageApexType
902 case zipApex:
903 return zipApexType
904 default:
905 panic(fmt.Errorf("unknown APEX type %d", a))
906 }
907}
908
Sundong Ahne9b55722019-09-06 17:37:42 +0900909func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900910 if !mctx.Module().Enabled() {
911 return
912 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900913 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900914 var variants []string
915 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
916 case "image":
917 variants = append(variants, imageApexType, flattenedApexType)
918 case "zip":
919 variants = append(variants, zipApexType)
920 case "both":
921 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
922 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900923 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900924 return
925 }
926
927 modules := mctx.CreateLocalVariations(variants...)
928
929 for i, v := range variants {
930 switch v {
931 case imageApexType:
932 modules[i].(*apexBundle).properties.ApexType = imageApex
933 case zipApexType:
934 modules[i].(*apexBundle).properties.ApexType = zipApex
935 case flattenedApexType:
936 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900937 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900938 modules[i].(*apexBundle).MakeAsSystemExt()
939 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900940 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900941 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900942 } else if _, ok := mctx.Module().(*OverrideApex); ok {
943 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900944 }
945}
946
Jooyung Handc782442019-11-01 03:14:38 +0900947var (
Colin Cross440e0d02020-06-11 11:32:11 -0700948 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900949)
950
Colin Cross440e0d02020-06-11 11:32:11 -0700951// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900952// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
953// which may cause compatibility issues. (e.g. libbinder)
954// Even though libbinder restricts its availability via 'apex_available' property and relies on
955// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
956// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -0700957func useVendorAllowList(config android.Config) []string {
958 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900959 return []string{
960 // swcodec uses "vendor" variants for smaller size
961 "com.android.media.swcodec",
962 "test_com.android.media.swcodec",
963 }
964 }).([]string)
965}
966
Colin Cross440e0d02020-06-11 11:32:11 -0700967// setUseVendorAllowListForTest overrides useVendorAllowList and must be
968// called before the first call to useVendorAllowList()
969func setUseVendorAllowListForTest(config android.Config, allowList []string) {
970 config.Once(useVendorAllowListKey, func() interface{} {
971 return allowList
Jooyung Handc782442019-11-01 03:14:38 +0900972 })
973}
974
Theotime Combes4ba38c12020-06-12 12:46:59 +0000975type fsType int
976
977const (
978 ext4 fsType = iota
979 f2fs
980)
981
982func (f fsType) string() string {
983 switch f {
984 case ext4:
985 return ext4FsType
986 case f2fs:
987 return f2fsFsType
988 default:
989 panic(fmt.Errorf("unknown APEX payload type %d", f))
990 }
991}
992
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900993func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
994 // direct deps of an APEX bundle are all part of the APEX bundle
995 return true
996}
997
Colin Cross0ea8ba82019-06-06 14:33:29 -0700998func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +0900999 moduleName := ctx.ModuleName()
1000 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1001 // we check with the pseudo module name to see if its certificate is overridden.
1002 if a.vndkApex {
1003 moduleName = vndkApexName
1004 }
1005 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001006 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001007 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001008 }
1009 return String(a.properties.Certificate)
1010}
1011
Colin Cross41955e82019-05-29 14:40:35 -07001012func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1013 switch tag {
1014 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001015 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001016 default:
1017 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001018 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001019}
1020
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001021func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001022 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001023}
1024
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001025func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1026 return proptools.Bool(a.properties.Test_only_no_hashtree)
1027}
1028
Dario Frenica913392020-04-27 18:21:11 +01001029func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1030 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1031}
1032
Jooyung Han85d61762020-06-24 23:50:26 +09001033func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1034 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001035 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001036 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001037 }
Jooyung Han85d61762020-06-24 23:50:26 +09001038
1039 var prefix string
1040 var vndkVersion string
1041 if deviceConfig.VndkVersion() != "" {
1042 if proptools.Bool(a.properties.Use_vendor) {
1043 prefix = cc.VendorVariationPrefix
1044 vndkVersion = deviceConfig.PlatformVndkVersion()
1045 } else if a.SocSpecific() || a.DeviceSpecific() {
1046 prefix = cc.VendorVariationPrefix
1047 vndkVersion = deviceConfig.VndkVersion()
1048 } else if a.ProductSpecific() {
1049 prefix = cc.ProductVariationPrefix
1050 vndkVersion = deviceConfig.ProductVndkVersion()
1051 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001052 }
Jooyung Han85d61762020-06-24 23:50:26 +09001053 if vndkVersion == "current" {
1054 vndkVersion = deviceConfig.PlatformVndkVersion()
1055 }
1056 if vndkVersion != "" {
1057 return prefix + vndkVersion
1058 }
1059 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001060}
1061
Jiyong Parkf97782b2019-02-13 20:28:58 +09001062func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1063 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1064 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1065 }
1066}
1067
Jiyong Park388ef3f2019-01-28 19:47:32 +09001068func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001069 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1070 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001071 }
1072
1073 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001074 globalSanitizerNames := []string{}
1075 if a.Host() {
1076 globalSanitizerNames = ctx.Config().SanitizeHost()
1077 } else {
1078 arches := ctx.Config().SanitizeDeviceArch()
1079 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1080 globalSanitizerNames = ctx.Config().SanitizeDevice()
1081 }
1082 }
1083 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001084}
1085
Jooyung Han8ce8db92020-05-15 19:05:05 +09001086func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1087 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1088 for _, target := range ctx.MultiTargets() {
1089 if target.Arch.ArchType.Multilib == "lib64" {
1090 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001091 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001092 {Mutator: "link", Variation: "shared"},
1093 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1094 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1095 break
1096 }
1097 }
1098 }
1099}
1100
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001101var _ cc.Coverage = (*apexBundle)(nil)
1102
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001103func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001104 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001105}
1106
1107func (a *apexBundle) PreventInstall() {
1108 a.properties.PreventInstall = true
1109}
1110
1111func (a *apexBundle) HideFromMake() {
1112 a.properties.HideFromMake = true
1113}
1114
Jiyong Park956305c2020-01-09 12:32:06 +09001115func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1116 a.properties.IsCoverageVariant = coverage
1117}
1118
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001119func (a *apexBundle) EnableCoverageIfNeeded() {}
1120
Jiyong Parkf653b052019-11-18 15:39:01 +09001121// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001122func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001123 // Decide the APEX-local directory by the multilib of the library
1124 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001125 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001126 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001127 case "lib32":
1128 dirInApex = "lib"
1129 case "lib64":
1130 dirInApex = "lib64"
1131 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001132 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001133 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001134 }
Jooyung Han35155c42020-02-06 17:33:20 +09001135 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001136 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001137 // Special case for Bionic libs and other libs installed with them. This is
1138 // to prevent those libs from being included in the search path
1139 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1140 // those libs in the Runtime APEX are available via the legacy paths in
1141 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1142 // to the legacy paths and thus will be loaded into the default linker
1143 // namespace (aka "platform" namespace). If the libs are directly in
1144 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1145 // into the runtime linker namespace, which will result in double loading of
1146 // them, which isn't supported.
1147 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001148 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001149
Jiyong Parkf653b052019-11-18 15:39:01 +09001150 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001151 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1152 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001153}
1154
Jiyong Park1833cef2019-12-13 13:28:36 +09001155func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001156 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001157 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001158 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001159 }
Jooyung Han35155c42020-02-06 17:33:20 +09001160 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001161 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001162 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1163 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001164 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001165 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001166 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001167}
1168
Jiyong Park1833cef2019-12-13 13:28:36 +09001169func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001170 dirInApex := "bin"
1171 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001172 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001173}
Jiyong Park1833cef2019-12-13 13:28:36 +09001174func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001175 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001176 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1177 if err != nil {
1178 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001179 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001180 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001181 fileToCopy := android.PathForOutput(ctx, s)
1182 // NB: Since go binaries are static we don't need the module for anything here, which is
1183 // good since the go tool is a blueprint.Module not an android.Module like we would
1184 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001185 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001186}
1187
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001188func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001189 dirInApex := filepath.Join("bin", sh.SubDir())
1190 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001191 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001192 af.symlinks = sh.Symlinks()
1193 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001194}
1195
Yo Chiange8128052020-07-23 20:09:18 +08001196type javaModule interface {
1197 android.Module
1198 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001199 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001200 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001201 LintDepSets() java.LintDepSets
1202
Jiyong Parka62aa232020-05-28 23:46:55 +09001203 Stem() string
1204}
1205
Yo Chiange8128052020-07-23 20:09:18 +08001206var _ javaModule = (*java.Library)(nil)
1207var _ javaModule = (*java.SdkLibrary)(nil)
1208var _ javaModule = (*java.DexImport)(nil)
1209var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001210
Yo Chiange8128052020-07-23 20:09:18 +08001211func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001212 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001213 fileToCopy := module.DexJarBuildPath()
1214 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1215 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1216 af.lintDepSets = module.LintDepSets()
1217 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001218 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001219}
1220
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001221func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001222 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001223 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001224 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001225}
1226
atrost6e126252020-01-27 17:01:16 +00001227func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1228 dirInApex := filepath.Join("etc", config.SubDir())
1229 fileToCopy := config.CompatConfig()
1230 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1231}
1232
Jiyong Park1833cef2019-12-13 13:28:36 +09001233func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001234 android.Module
1235 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001236 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001237 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001238 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001239 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001240 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001241}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001242 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001243 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001244 appDir = "priv-app"
1245 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001246 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001247 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001248 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001249 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001250 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001251
1252 if app, ok := aapp.(interface {
1253 OverriddenManifestPackageName() string
1254 }); ok {
1255 af.overriddenPackageName = app.OverriddenManifestPackageName()
1256 }
Jiyong Park618922e2020-01-08 13:35:43 +09001257 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001258}
1259
Jiyong Park69aeba92020-04-24 21:16:36 +09001260func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1261 rroDir := "overlay"
1262 dirInApex := filepath.Join(rroDir, rro.Theme())
1263 fileToCopy := rro.OutputFile()
1264 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1265 af.certificate = rro.Certificate()
1266
1267 if a, ok := rro.(interface {
1268 OverriddenManifestPackageName() string
1269 }); ok {
1270 af.overriddenPackageName = a.OverriddenManifestPackageName()
1271 }
1272 return af
1273}
1274
markchien2f59ec92020-09-02 16:23:38 +08001275func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1276 dirInApex := filepath.Join("etc", "bpf")
1277 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1278}
1279
Roland Levillain935639d2019-08-13 14:55:28 +01001280// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1281type flattenedApexContext struct {
1282 android.ModuleContext
1283}
1284
1285func (c *flattenedApexContext) InstallBypassMake() bool {
1286 return true
1287}
1288
Jiyong Park201cedd2020-02-07 17:25:49 +09001289// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001290func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001291 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001292 am, ok := child.(android.ApexModule)
1293 if !ok || !am.CanHaveApexVariants() {
1294 return false
1295 }
1296
Colin Cross56a83212020-09-15 18:30:11 -07001297 childApexInfo := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1298
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001299 dt := ctx.OtherModuleDependencyTag(child)
1300
1301 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1302 return false
1303 }
1304
Jiyong Park0f80c182020-01-31 02:49:53 +09001305 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001306 if adt, ok := dt.(dependencyTag); ok {
1307 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001308 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001309 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001310 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001311 return false
1312 }
1313
1314 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Cross56a83212020-09-15 18:30:11 -07001315 if android.InList(ctx.ModuleName(), childApexInfo.InApexes) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001316 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001317 }
1318
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001319 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001320 })
1321}
1322
Dan Albertc8060532020-07-22 22:32:17 -07001323func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
Jooyung Han749dc692020-04-15 11:03:39 +09001324 ver := proptools.String(a.properties.Min_sdk_version)
1325 if ver == "" {
Dan Albert0b176c82020-07-23 16:43:25 -07001326 return android.FutureApiLevel
Jooyung Han749dc692020-04-15 11:03:39 +09001327 }
Dan Albertc8060532020-07-22 22:32:17 -07001328 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
Jooyung Hanaed150d2020-04-02 01:41:41 +09001329 if err != nil {
1330 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Dan Albertc8060532020-07-22 22:32:17 -07001331 return android.NoneApiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09001332 }
Dan Albertc8060532020-07-22 22:32:17 -07001333 if apiLevel.IsPreview() {
1334 // All codenames should build against "current".
Dan Albert0b176c82020-07-23 16:43:25 -07001335 return android.FutureApiLevel
Dan Albertc8060532020-07-22 22:32:17 -07001336 }
1337 return apiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09001338}
1339
Artur Satayev849f8442020-04-28 14:57:42 +01001340func (a *apexBundle) Updatable() bool {
1341 return proptools.Bool(a.properties.Updatable)
1342}
1343
1344var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1345
Jiyong Park201cedd2020-02-07 17:25:49 +09001346// Ensures that the dependencies are marked as available for this APEX
1347func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1348 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1349 if ctx.Host() || a.testApex || a.vndkApex {
1350 return
1351 }
1352
Jooyung Han85d61762020-06-24 23:50:26 +09001353 // Because APEXes targeting other than system/system_ext partitions
1354 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09001355 if a.SocSpecific() || a.DeviceSpecific() ||
1356 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001357 return
1358 }
1359
Jiyong Park58d10902020-03-28 14:43:19 +09001360 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1361 // Requiring them and their transitive depencies with apex_available is not right
1362 // because they just add noise.
1363 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1364 return
1365 }
1366
Jooyung Han749dc692020-04-15 11:03:39 +09001367 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001368 if externalDep {
1369 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1370 return false
1371 }
1372
Jiyong Park201cedd2020-02-07 17:25:49 +09001373 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001374 fromName := ctx.OtherModuleName(from)
1375 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001376
1377 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1378 // do any of its dependencies.
1379 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1380 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1381 return false
1382 }
1383
Colin Cross440e0d02020-06-11 11:32:11 -07001384 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001385 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001386 }
Steven Moreland6e36cd62020-10-22 01:08:35 +00001387 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001388 // Visit this module's dependencies to check and report any issues with their availability.
1389 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001390 })
1391}
1392
Jooyung Han548640b2020-04-27 12:10:30 +09001393func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001394 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001395 if String(a.properties.Min_sdk_version) == "" {
1396 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1397 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001398
1399 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001400 }
1401}
1402
Jooyung Han749dc692020-04-15 11:03:39 +09001403func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1404 if a.testApex || a.vndkApex {
1405 return
1406 }
1407 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1408 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1409 return
1410 }
Dan Albertc8060532020-07-22 22:32:17 -07001411 // apexBundle::minSdkVersion reports its own errors.
1412 minSdkVersion := a.minSdkVersion(ctx)
1413 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09001414}
1415
Jiyong Park7d95a512020-05-10 15:16:24 +09001416// Ensures that a lib providing stub isn't statically linked
1417func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1418 // Practically, we only care about regular APEXes on the device.
1419 if ctx.Host() || a.testApex || a.vndkApex {
1420 return
1421 }
1422
Colin Cross56a83212020-09-15 18:30:11 -07001423 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1424
Jooyung Han749dc692020-04-15 11:03:39 +09001425 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09001426 if ccm, ok := to.(*cc.Module); ok {
1427 apexName := ctx.ModuleName()
1428 fromName := ctx.OtherModuleName(from)
1429 toName := ctx.OtherModuleName(to)
1430
1431 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1432 // do any of its dependencies.
1433 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1434 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1435 return false
1436 }
1437
Jiyong Park7d95a512020-05-10 15:16:24 +09001438 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1439 // It can't make the static dependencies dynamic because it can't
1440 // do the dynamic linking for itself.
1441 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1442 return false
1443 }
1444
Colin Cross56a83212020-09-15 18:30:11 -07001445 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
Jiyong Park7d95a512020-05-10 15:16:24 +09001446 if isStubLibraryFromOtherApex && !externalDep {
1447 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1448 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1449 }
1450
1451 }
1452 return true
1453 })
1454}
1455
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001456func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01001457 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09001458 switch a.properties.ApexType {
1459 case imageApex:
1460 if buildFlattenedAsDefault {
1461 a.suffix = imageApexSuffix
1462 } else {
1463 a.suffix = ""
1464 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001465
1466 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001467 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001468 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001469 }
1470 case zipApex:
1471 if proptools.String(a.properties.Payload_type) == "zip" {
1472 a.suffix = ""
1473 a.primaryApexType = true
1474 } else {
1475 a.suffix = zipApexSuffix
1476 }
1477 case flattenedApex:
1478 if buildFlattenedAsDefault {
1479 a.suffix = ""
1480 a.primaryApexType = true
1481 } else {
1482 a.suffix = flattenedSuffix
1483 }
Alex Light5098a612018-11-29 17:12:15 -08001484 }
1485
Roland Levillain630846d2019-06-26 12:48:34 +01001486 if len(a.properties.Tests) > 0 && !a.testApex {
1487 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1488 return
1489 }
1490
Jiyong Park0f80c182020-01-31 02:49:53 +09001491 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001492 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001493 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001494 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001495
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001496 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1497
Jooyung Hane1633032019-08-01 17:41:43 +09001498 // native lib dependencies
1499 var provideNativeLibs []string
1500 var requireNativeLibs []string
1501
Jiyong Parkf653b052019-11-18 15:39:01 +09001502 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09001503 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001504 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001505 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001506 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1507 return false
1508 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001509 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001510 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001511 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001512 case sharedLibTag, jniLibTag:
1513 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001514 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001515 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1516 fi.isJniLib = isJniLib
1517 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001518 // Collect the list of stub-providing libs except:
1519 // - VNDK libs are only for vendors
1520 // - bootstrap bionic libs are treated as provided by system
1521 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001522 provideNativeLibs = append(provideNativeLibs, fi.Stem())
1523 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001524 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001525 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001526 propertyName := "native_shared_libs"
1527 if isJniLib {
1528 propertyName = "jni_libs"
1529 }
1530 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001531 }
1532 case executableTag:
1533 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001534 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001535 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001536 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001537 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001538 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001539 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001540 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001541 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001542 } else {
Alex Light778127a2019-02-27 14:19:50 -08001543 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001544 }
1545 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001546 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01001547 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08001548 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001549 if !af.Ok() {
1550 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1551 return false
1552 }
1553 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001554 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001555 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001556 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001557 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001558 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001559 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001560 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001561 return true // track transitive dependencies
1562 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001563 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001564 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001565 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001566 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1567 appDir := "app"
1568 if ap.Privileged() {
1569 appDir = "priv-app"
1570 }
Yo Chiange8128052020-07-23 20:09:18 +08001571 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001572 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1573 af.certificate = java.PresignedCertificate
1574 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001575 } else {
1576 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1577 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001578 case rroTag:
1579 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1580 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1581 } else {
1582 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1583 }
markchien2f59ec92020-09-02 16:23:38 +08001584 case bpfTag:
1585 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1586 filesToCopy, _ := bpfProgram.OutputFiles("")
1587 for _, bpfFile := range filesToCopy {
1588 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1589 }
1590 } else {
1591 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1592 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001593 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001594 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001595 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001596 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1597 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001598 } else {
atrost6e126252020-01-27 17:01:16 +00001599 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001600 }
Roland Levillain630846d2019-06-26 12:48:34 +01001601 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001602 if ccTest, ok := child.(*cc.Module); ok {
1603 if ccTest.IsTestPerSrcAllTestsVariation() {
1604 // Multiple-output test module (where `test_per_src: true`).
1605 //
1606 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1607 // We do not add this variation to `filesInfo`, as it has no output;
1608 // however, we do add the other variations of this module as indirect
1609 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001610 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001611 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001612 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001613 af.class = nativeTest
1614 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001615 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001616 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001617 } else {
1618 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1619 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001620 case keyTag:
1621 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001622 a.private_key_file = key.private_key_file
1623 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001624 } else {
1625 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001626 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001627 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001628 case certificateTag:
1629 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001630 a.container_certificate_file = dep.Certificate.Pem
1631 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001632 } else {
1633 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1634 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001635 case android.PrebuiltDepTag:
1636 // If the prebuilt is force disabled, remember to delete the prebuilt file
1637 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001638 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001639 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1640 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001641 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001642 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001643 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001644 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001645 // We cannot use a switch statement on `depTag` here as the checked
1646 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001647 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001648 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001649 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001650 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001651 return false
1652 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001653 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1654 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07001655 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1656 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001657 // If the dependency is a stubs lib, don't include it in this APEX,
1658 // but make sure that the lib is installed on the device.
1659 // In case no APEX is having the lib, the lib is installed to the system
1660 // partition.
1661 //
1662 // Always include if we are a host-apex however since those won't have any
1663 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001664 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001665 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07001666 name := cc.ImplementationModuleName(ctx)
1667
1668 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001669 // we don't use subName(.vendor) for a "use_vendor: true" apex
1670 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07001671 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001672 }
1673 if !android.InList(name, a.requiredDeps) {
1674 a.requiredDeps = append(a.requiredDeps, name)
1675 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001676 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001677 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001678 // Don't track further
1679 return false
1680 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 filesInfo = append(filesInfo, af)
1682 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001683 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001684 } else if cc.IsTestPerSrcDepTag(depTag) {
1685 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001686 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001687 // Handle modules created as `test_per_src` variations of a single test module:
1688 // use the name of the generated test binary (`fileToCopy`) instead of the name
1689 // of the original test module (`depName`, shared by all `test_per_src`
1690 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001691 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001692 // these are not considered transitive dep
1693 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001694 filesInfo = append(filesInfo, af)
1695 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001696 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001697 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001698 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1699 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001700 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001701 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001702 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1703 }
Colin Cross56a83212020-09-15 18:30:11 -07001704 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1705 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001706 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001707 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001708 }
1709 }
1710 }
1711 return false
1712 })
1713
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001714 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1715 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1716 // via the global boot image config.
1717 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00001718 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001719 dirInApex := filepath.Join("javalib", arch.String())
1720 for _, f := range files {
1721 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001722 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001723 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001724 }
1725 }
1726 }
1727
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001728 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001729 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1730 return
1731 }
1732
Jiyong Park8fd61922018-11-08 02:50:25 +09001733 // remove duplicates in filesInfo
1734 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001735 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001736 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001737 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001738 if e, ok := encountered[dest]; !ok {
1739 encountered[dest] = f
1740 } else {
1741 // If a module is directly included and also transitively depended on
1742 // consider it as directly included.
1743 e.transitiveDep = e.transitiveDep && f.transitiveDep
1744 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001745 }
1746 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001747 var result []apexFile
1748 for _, v := range encountered {
1749 result = append(result, v)
1750 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001751 return result
1752 }
1753 filesInfo = removeDup(filesInfo)
1754
1755 // to have consistent build rules
1756 sort.Slice(filesInfo, func(i, j int) bool {
1757 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1758 })
1759
Jiyong Park8fd61922018-11-08 02:50:25 +09001760 a.installDir = android.PathForModuleInstall(ctx, "apex")
1761 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001762
Theotime Combes4ba38c12020-06-12 12:46:59 +00001763 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1764 case ext4FsType:
1765 a.payloadFsType = ext4
1766 case f2fsFsType:
1767 a.payloadFsType = f2fs
1768 default:
1769 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
1770 }
1771
Jiyong Park7cd10e32020-01-14 09:22:18 +09001772 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1773 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1774 // the same library in the system partition, thus effectively sharing the same libraries
1775 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1776 // in the APEX.
1777 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
1778 a.installable() &&
1779 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001780
Jooyung Han85d61762020-06-24 23:50:26 +09001781 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1782 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09001783 if a.SocSpecific() || a.DeviceSpecific() ||
1784 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001785 a.linkToSystemLib = false
1786 }
1787
Jiyong Park9d677202020-02-19 16:29:35 +09001788 // We don't need the optimization for updatable APEXes, as it might give false signal
1789 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01001790 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09001791 a.linkToSystemLib = false
1792 }
1793
Jiyong Park638d30e2020-02-26 18:27:19 +09001794 // We also don't want the optimization for host APEXes, because it doesn't make sense.
1795 if ctx.Host() {
1796 a.linkToSystemLib = false
1797 }
1798
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001799 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001800 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1801
Jooyung Han580eb4f2020-06-24 19:33:06 +09001802 a.buildFileContexts(ctx)
1803
Jooyung Han01a3ee22019-11-02 02:52:25 +09001804 a.setCertificateAndPrivateKey(ctx)
1805 if a.properties.ApexType == flattenedApex {
1806 a.buildFlattenedApex(ctx)
1807 } else {
1808 a.buildUnflattenedApex(ctx)
1809 }
1810
Jooyung Han002ab682020-01-08 01:57:58 +09001811 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09001812
1813 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07001814
1815 a.buildLintReports(ctx)
Anton Hansson82d502a2020-11-11 12:33:14 +00001816
1817 a.distFiles = a.GenerateTaggedDistFiles(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001818}
1819
Artur Satayev8cf899a2020-04-15 17:29:42 +01001820// Enforce that Java deps of the apex are using stable SDKs to compile
1821func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
1822 // Visit direct deps only. As long as we guarantee top-level deps are using
1823 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
1824 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1825 tag := ctx.OtherModuleDependencyTag(module)
1826 switch tag {
1827 case javaLibTag, androidAppTag:
1828 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
1829 if err := m.CheckStableSdkVersion(); err != nil {
1830 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
1831 }
1832 }
1833 }
1834 })
1835}
1836
Colin Cross440e0d02020-06-11 11:32:11 -07001837func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001838 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00001839 moduleName = normalizeModuleName(moduleName)
1840
Colin Cross440e0d02020-06-11 11:32:11 -07001841 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00001842 return true
1843 }
1844
1845 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07001846 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00001847 return true
1848 }
1849
1850 return false
1851}
1852
1853func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09001854 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
1855 // system. Trim the prefix for the check since they are confusing
1856 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
1857 if strings.HasPrefix(moduleName, "libclang_rt.") {
1858 // This module has many arch variants that depend on the product being built.
1859 // We don't want to list them all
1860 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001861 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09001862 if strings.HasPrefix(moduleName, "androidx.") {
1863 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
1864 moduleName = "androidx"
1865 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00001866 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001867}
1868
Jooyung Han344d5432019-08-23 11:17:39 +09001869func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001870 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001871 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001872 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001873 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001874 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001875 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001876 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001877 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001878 return module
1879}
Jiyong Park30ca9372019-02-07 16:27:23 +09001880
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001881func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001882 bundle := newApexBundle()
1883 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001884 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001885 return bundle
1886}
1887
Jiyong Parkfce0b422020-02-11 03:56:06 +09001888// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
1889// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09001890func testApexBundleFactory() android.Module {
1891 bundle := newApexBundle()
1892 bundle.testApex = true
1893 return bundle
1894}
1895
Jiyong Parkfce0b422020-02-11 03:56:06 +09001896// apex packages other modules into an APEX file which is a packaging format for system-level
1897// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09001898func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001899 return newApexBundle()
1900}
1901
Jiyong Park30ca9372019-02-07 16:27:23 +09001902//
1903// Defaults
1904//
1905type Defaults struct {
1906 android.ModuleBase
1907 android.DefaultsModuleBase
1908}
1909
Jiyong Park30ca9372019-02-07 16:27:23 +09001910func defaultsFactory() android.Module {
1911 return DefaultsFactory()
1912}
1913
1914func DefaultsFactory(props ...interface{}) android.Module {
1915 module := &Defaults{}
1916
1917 module.AddProperties(props...)
1918 module.AddProperties(
1919 &apexBundleProperties{},
1920 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001921 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001922 )
1923
1924 android.InitDefaultsModule(module)
1925 return module
1926}
Jiyong Park5d790c32019-11-15 18:40:32 +09001927
1928//
1929// OverrideApex
1930//
1931type OverrideApex struct {
1932 android.ModuleBase
1933 android.OverrideModuleBase
1934}
1935
1936func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1937 // All the overrides happen in the base module.
1938}
1939
1940// override_apex is used to create an apex module based on another apex module
1941// by overriding some of its properties.
1942func overrideApexFactory() android.Module {
1943 m := &OverrideApex{}
1944 m.AddProperties(&overridableProperties{})
1945
1946 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1947 android.InitOverrideModule(m)
1948 return m
1949}
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001950
1951var (
1952 apexAvailBaseline = makeApexAvailableBaseline()
1953 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
1954)
1955
1956// Transform the map of apex -> modules to module -> apexes.
1957func invertApexBaseline(m map[string][]string) map[string][]string {
1958 r := make(map[string][]string)
1959 for apex, modules := range m {
1960 for _, module := range modules {
1961 r[module] = append(r[module], apex)
1962 }
1963 }
1964 return r
1965}
1966
1967// Retrieve the baseline of apexes to which the supplied module belongs.
1968func BaselineApexAvailable(moduleName string) []string {
1969 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
1970}
1971
1972// This is a map from apex to modules, which overrides the
1973// apex_available setting for that particular module to make
1974// it available for the apex regardless of its setting.
1975// TODO(b/147364041): remove this
1976func makeApexAvailableBaseline() map[string][]string {
1977 // The "Module separator"s below are employed to minimize merge conflicts.
1978 m := make(map[string][]string)
1979 //
1980 // Module separator
1981 //
1982 m["com.android.appsearch"] = []string{
1983 "icing-java-proto-lite",
1984 "libprotobuf-java-lite",
1985 }
1986 //
1987 // Module separator
1988 //
1989 m["com.android.bluetooth.updatable"] = []string{
1990 "android.hardware.audio.common@5.0",
1991 "android.hardware.bluetooth.a2dp@1.0",
1992 "android.hardware.bluetooth.audio@2.0",
1993 "android.hardware.bluetooth@1.0",
1994 "android.hardware.bluetooth@1.1",
1995 "android.hardware.graphics.bufferqueue@1.0",
1996 "android.hardware.graphics.bufferqueue@2.0",
1997 "android.hardware.graphics.common@1.0",
1998 "android.hardware.graphics.common@1.1",
1999 "android.hardware.graphics.common@1.2",
2000 "android.hardware.media@1.0",
2001 "android.hidl.safe_union@1.0",
2002 "android.hidl.token@1.0",
2003 "android.hidl.token@1.0-utils",
2004 "avrcp-target-service",
2005 "avrcp_headers",
2006 "bluetooth-protos-lite",
2007 "bluetooth.mapsapi",
2008 "com.android.vcard",
2009 "dnsresolver_aidl_interface-V2-java",
2010 "ipmemorystore-aidl-interfaces-V5-java",
2011 "ipmemorystore-aidl-interfaces-java",
2012 "internal_include_headers",
2013 "lib-bt-packets",
2014 "lib-bt-packets-avrcp",
2015 "lib-bt-packets-base",
2016 "libFraunhoferAAC",
2017 "libaudio-a2dp-hw-utils",
2018 "libaudio-hearing-aid-hw-utils",
2019 "libbinder_headers",
2020 "libbluetooth",
2021 "libbluetooth-types",
2022 "libbluetooth-types-header",
2023 "libbluetooth_gd",
2024 "libbluetooth_headers",
2025 "libbluetooth_jni",
2026 "libbt-audio-hal-interface",
2027 "libbt-bta",
2028 "libbt-common",
2029 "libbt-hci",
2030 "libbt-platform-protos-lite",
2031 "libbt-protos-lite",
2032 "libbt-sbc-decoder",
2033 "libbt-sbc-encoder",
2034 "libbt-stack",
2035 "libbt-utils",
2036 "libbtcore",
2037 "libbtdevice",
2038 "libbte",
2039 "libbtif",
2040 "libchrome",
2041 "libevent",
2042 "libfmq",
2043 "libg722codec",
2044 "libgui_headers",
2045 "libmedia_headers",
2046 "libmodpb64",
2047 "libosi",
2048 "libstagefright_foundation_headers",
2049 "libstagefright_headers",
2050 "libstatslog",
2051 "libstatssocket",
2052 "libtinyxml2",
2053 "libudrv-uipc",
2054 "libz",
2055 "media_plugin_headers",
2056 "net-utils-services-common",
2057 "netd_aidl_interface-unstable-java",
2058 "netd_event_listener_interface-java",
2059 "netlink-client",
2060 "networkstack-client",
2061 "sap-api-java-static",
2062 "services.net",
2063 }
2064 //
2065 // Module separator
2066 //
2067 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2068 //
2069 // Module separator
2070 //
2071 m["com.android.extservices"] = []string{
2072 "error_prone_annotations",
2073 "ExtServices-core",
2074 "ExtServices",
2075 "libtextclassifier-java",
2076 "libz_current",
2077 "textclassifier-statsd",
2078 "TextClassifierNotificationLibNoManifest",
2079 "TextClassifierServiceLibNoManifest",
2080 }
2081 //
2082 // Module separator
2083 //
2084 m["com.android.neuralnetworks"] = []string{
2085 "android.hardware.neuralnetworks@1.0",
2086 "android.hardware.neuralnetworks@1.1",
2087 "android.hardware.neuralnetworks@1.2",
2088 "android.hardware.neuralnetworks@1.3",
2089 "android.hidl.allocator@1.0",
2090 "android.hidl.memory.token@1.0",
2091 "android.hidl.memory@1.0",
2092 "android.hidl.safe_union@1.0",
2093 "libarect",
2094 "libbuildversion",
2095 "libmath",
2096 "libprocpartition",
2097 "libsync",
2098 }
2099 //
2100 // Module separator
2101 //
2102 m["com.android.media"] = []string{
2103 "android.frameworks.bufferhub@1.0",
2104 "android.hardware.cas.native@1.0",
2105 "android.hardware.cas@1.0",
2106 "android.hardware.configstore-utils",
2107 "android.hardware.configstore@1.0",
2108 "android.hardware.configstore@1.1",
2109 "android.hardware.graphics.allocator@2.0",
2110 "android.hardware.graphics.allocator@3.0",
2111 "android.hardware.graphics.bufferqueue@1.0",
2112 "android.hardware.graphics.bufferqueue@2.0",
2113 "android.hardware.graphics.common@1.0",
2114 "android.hardware.graphics.common@1.1",
2115 "android.hardware.graphics.common@1.2",
2116 "android.hardware.graphics.mapper@2.0",
2117 "android.hardware.graphics.mapper@2.1",
2118 "android.hardware.graphics.mapper@3.0",
2119 "android.hardware.media.omx@1.0",
2120 "android.hardware.media@1.0",
2121 "android.hidl.allocator@1.0",
2122 "android.hidl.memory.token@1.0",
2123 "android.hidl.memory@1.0",
2124 "android.hidl.token@1.0",
2125 "android.hidl.token@1.0-utils",
2126 "bionic_libc_platform_headers",
2127 "exoplayer2-extractor",
2128 "exoplayer2-extractor-annotation-stubs",
2129 "gl_headers",
2130 "jsr305",
2131 "libEGL",
2132 "libEGL_blobCache",
2133 "libEGL_getProcAddress",
2134 "libFLAC",
2135 "libFLAC-config",
2136 "libFLAC-headers",
2137 "libGLESv2",
2138 "libaacextractor",
2139 "libamrextractor",
2140 "libarect",
2141 "libaudio_system_headers",
2142 "libaudioclient",
2143 "libaudioclient_headers",
2144 "libaudiofoundation",
2145 "libaudiofoundation_headers",
2146 "libaudiomanager",
2147 "libaudiopolicy",
2148 "libaudioutils",
2149 "libaudioutils_fixedfft",
2150 "libbinder_headers",
2151 "libbluetooth-types-header",
2152 "libbufferhub",
2153 "libbufferhub_headers",
2154 "libbufferhubqueue",
2155 "libc_malloc_debug_backtrace",
2156 "libcamera_client",
2157 "libcamera_metadata",
2158 "libdvr_headers",
2159 "libexpat",
2160 "libfifo",
2161 "libflacextractor",
2162 "libgrallocusage",
2163 "libgraphicsenv",
2164 "libgui",
2165 "libgui_headers",
2166 "libhardware_headers",
2167 "libinput",
2168 "liblzma",
2169 "libmath",
2170 "libmedia",
2171 "libmedia_codeclist",
2172 "libmedia_headers",
2173 "libmedia_helper",
2174 "libmedia_helper_headers",
2175 "libmedia_midiiowrapper",
2176 "libmedia_omx",
2177 "libmediautils",
2178 "libmidiextractor",
2179 "libmkvextractor",
2180 "libmp3extractor",
2181 "libmp4extractor",
2182 "libmpeg2extractor",
2183 "libnativebase_headers",
2184 "libnativewindow_headers",
2185 "libnblog",
2186 "liboggextractor",
2187 "libpackagelistparser",
2188 "libpdx",
2189 "libpdx_default_transport",
2190 "libpdx_headers",
2191 "libpdx_uds",
2192 "libprocinfo",
2193 "libspeexresampler",
2194 "libspeexresampler",
2195 "libstagefright_esds",
2196 "libstagefright_flacdec",
2197 "libstagefright_flacdec",
2198 "libstagefright_foundation",
2199 "libstagefright_foundation_headers",
2200 "libstagefright_foundation_without_imemory",
2201 "libstagefright_headers",
2202 "libstagefright_id3",
2203 "libstagefright_metadatautils",
2204 "libstagefright_mpeg2extractor",
2205 "libstagefright_mpeg2support",
2206 "libsync",
2207 "libui",
2208 "libui_headers",
2209 "libunwindstack",
2210 "libvibrator",
2211 "libvorbisidec",
2212 "libwavextractor",
2213 "libwebm",
2214 "media_ndk_headers",
2215 "media_plugin_headers",
2216 "updatable-media",
2217 }
2218 //
2219 // Module separator
2220 //
2221 m["com.android.media.swcodec"] = []string{
2222 "android.frameworks.bufferhub@1.0",
2223 "android.hardware.common-ndk_platform",
2224 "android.hardware.configstore-utils",
2225 "android.hardware.configstore@1.0",
2226 "android.hardware.configstore@1.1",
2227 "android.hardware.graphics.allocator@2.0",
2228 "android.hardware.graphics.allocator@3.0",
2229 "android.hardware.graphics.allocator@4.0",
2230 "android.hardware.graphics.bufferqueue@1.0",
2231 "android.hardware.graphics.bufferqueue@2.0",
2232 "android.hardware.graphics.common-ndk_platform",
2233 "android.hardware.graphics.common@1.0",
2234 "android.hardware.graphics.common@1.1",
2235 "android.hardware.graphics.common@1.2",
2236 "android.hardware.graphics.mapper@2.0",
2237 "android.hardware.graphics.mapper@2.1",
2238 "android.hardware.graphics.mapper@3.0",
2239 "android.hardware.graphics.mapper@4.0",
2240 "android.hardware.media.bufferpool@2.0",
2241 "android.hardware.media.c2@1.0",
2242 "android.hardware.media.c2@1.1",
2243 "android.hardware.media.omx@1.0",
2244 "android.hardware.media@1.0",
2245 "android.hardware.media@1.0",
2246 "android.hidl.memory.token@1.0",
2247 "android.hidl.memory@1.0",
2248 "android.hidl.safe_union@1.0",
2249 "android.hidl.token@1.0",
2250 "android.hidl.token@1.0-utils",
2251 "libEGL",
2252 "libFLAC",
2253 "libFLAC-config",
2254 "libFLAC-headers",
2255 "libFraunhoferAAC",
2256 "libLibGuiProperties",
2257 "libarect",
2258 "libaudio_system_headers",
2259 "libaudioutils",
2260 "libaudioutils",
2261 "libaudioutils_fixedfft",
2262 "libavcdec",
2263 "libavcenc",
2264 "libavservices_minijail",
2265 "libavservices_minijail",
2266 "libbinder_headers",
2267 "libbinderthreadstateutils",
2268 "libbluetooth-types-header",
2269 "libbufferhub_headers",
2270 "libcodec2",
2271 "libcodec2_headers",
2272 "libcodec2_hidl@1.0",
2273 "libcodec2_hidl@1.1",
2274 "libcodec2_internal",
2275 "libcodec2_soft_aacdec",
2276 "libcodec2_soft_aacenc",
2277 "libcodec2_soft_amrnbdec",
2278 "libcodec2_soft_amrnbenc",
2279 "libcodec2_soft_amrwbdec",
2280 "libcodec2_soft_amrwbenc",
2281 "libcodec2_soft_av1dec_gav1",
2282 "libcodec2_soft_avcdec",
2283 "libcodec2_soft_avcenc",
2284 "libcodec2_soft_common",
2285 "libcodec2_soft_flacdec",
2286 "libcodec2_soft_flacenc",
2287 "libcodec2_soft_g711alawdec",
2288 "libcodec2_soft_g711mlawdec",
2289 "libcodec2_soft_gsmdec",
2290 "libcodec2_soft_h263dec",
2291 "libcodec2_soft_h263enc",
2292 "libcodec2_soft_hevcdec",
2293 "libcodec2_soft_hevcenc",
2294 "libcodec2_soft_mp3dec",
2295 "libcodec2_soft_mpeg2dec",
2296 "libcodec2_soft_mpeg4dec",
2297 "libcodec2_soft_mpeg4enc",
2298 "libcodec2_soft_opusdec",
2299 "libcodec2_soft_opusenc",
2300 "libcodec2_soft_rawdec",
2301 "libcodec2_soft_vorbisdec",
2302 "libcodec2_soft_vp8dec",
2303 "libcodec2_soft_vp8enc",
2304 "libcodec2_soft_vp9dec",
2305 "libcodec2_soft_vp9enc",
2306 "libcodec2_vndk",
2307 "libdvr_headers",
2308 "libfmq",
2309 "libfmq",
2310 "libgav1",
2311 "libgralloctypes",
2312 "libgrallocusage",
2313 "libgraphicsenv",
2314 "libgsm",
2315 "libgui_bufferqueue_static",
2316 "libgui_headers",
2317 "libhardware",
2318 "libhardware_headers",
2319 "libhevcdec",
2320 "libhevcenc",
2321 "libion",
2322 "libjpeg",
2323 "liblzma",
2324 "libmath",
2325 "libmedia_codecserviceregistrant",
2326 "libmedia_headers",
2327 "libmpeg2dec",
2328 "libnativebase_headers",
2329 "libnativewindow_headers",
2330 "libpdx_headers",
2331 "libscudo_wrapper",
2332 "libsfplugin_ccodec_utils",
2333 "libspeexresampler",
2334 "libstagefright_amrnb_common",
2335 "libstagefright_amrnbdec",
2336 "libstagefright_amrnbenc",
2337 "libstagefright_amrwbdec",
2338 "libstagefright_amrwbenc",
2339 "libstagefright_bufferpool@2.0.1",
2340 "libstagefright_bufferqueue_helper",
2341 "libstagefright_enc_common",
2342 "libstagefright_flacdec",
2343 "libstagefright_foundation",
2344 "libstagefright_foundation_headers",
2345 "libstagefright_headers",
2346 "libstagefright_m4vh263dec",
2347 "libstagefright_m4vh263enc",
2348 "libstagefright_mp3dec",
2349 "libsync",
2350 "libui",
2351 "libui_headers",
2352 "libunwindstack",
2353 "libvorbisidec",
2354 "libvpx",
2355 "libyuv",
2356 "libyuv_static",
2357 "media_ndk_headers",
2358 "media_plugin_headers",
2359 "mediaswcodec",
2360 }
2361 //
2362 // Module separator
2363 //
2364 m["com.android.mediaprovider"] = []string{
2365 "MediaProvider",
2366 "MediaProviderGoogle",
2367 "fmtlib_ndk",
2368 "libbase_ndk",
2369 "libfuse",
2370 "libfuse_jni",
2371 }
2372 //
2373 // Module separator
2374 //
2375 m["com.android.permission"] = []string{
2376 "car-ui-lib",
2377 "iconloader",
2378 "kotlin-annotations",
2379 "kotlin-stdlib",
2380 "kotlin-stdlib-jdk7",
2381 "kotlin-stdlib-jdk8",
2382 "kotlinx-coroutines-android",
2383 "kotlinx-coroutines-android-nodeps",
2384 "kotlinx-coroutines-core",
2385 "kotlinx-coroutines-core-nodeps",
2386 "permissioncontroller-statsd",
2387 "GooglePermissionController",
2388 "PermissionController",
2389 "SettingsLibActionBarShadow",
2390 "SettingsLibAppPreference",
2391 "SettingsLibBarChartPreference",
2392 "SettingsLibLayoutPreference",
2393 "SettingsLibProgressBar",
2394 "SettingsLibSearchWidget",
2395 "SettingsLibSettingsTheme",
2396 "SettingsLibRestrictedLockUtils",
2397 "SettingsLibHelpUtils",
2398 }
2399 //
2400 // Module separator
2401 //
2402 m["com.android.runtime"] = []string{
2403 "bionic_libc_platform_headers",
2404 "libarm-optimized-routines-math",
2405 "libc_aeabi",
2406 "libc_bionic",
2407 "libc_bionic_ndk",
2408 "libc_bootstrap",
2409 "libc_common",
2410 "libc_common_shared",
2411 "libc_common_static",
2412 "libc_dns",
2413 "libc_dynamic_dispatch",
2414 "libc_fortify",
2415 "libc_freebsd",
2416 "libc_freebsd_large_stack",
2417 "libc_gdtoa",
2418 "libc_init_dynamic",
2419 "libc_init_static",
2420 "libc_jemalloc_wrapper",
2421 "libc_netbsd",
2422 "libc_nomalloc",
2423 "libc_nopthread",
2424 "libc_openbsd",
2425 "libc_openbsd_large_stack",
2426 "libc_openbsd_ndk",
2427 "libc_pthread",
2428 "libc_static_dispatch",
2429 "libc_syscalls",
2430 "libc_tzcode",
2431 "libc_unwind_static",
2432 "libdebuggerd",
2433 "libdebuggerd_common_headers",
2434 "libdebuggerd_handler_core",
2435 "libdebuggerd_handler_fallback",
2436 "libdl_static",
2437 "libjemalloc5",
2438 "liblinker_main",
2439 "liblinker_malloc",
2440 "liblz4",
2441 "liblzma",
2442 "libprocinfo",
2443 "libpropertyinfoparser",
2444 "libscudo",
2445 "libstdc++",
2446 "libsystemproperties",
2447 "libtombstoned_client_static",
2448 "libunwindstack",
2449 "libz",
2450 "libziparchive",
2451 }
2452 //
2453 // Module separator
2454 //
2455 m["com.android.tethering"] = []string{
2456 "android.hardware.tetheroffload.config-V1.0-java",
2457 "android.hardware.tetheroffload.control-V1.0-java",
2458 "android.hidl.base-V1.0-java",
2459 "libcgrouprc",
2460 "libcgrouprc_format",
2461 "libtetherutilsjni",
2462 "libvndksupport",
2463 "net-utils-framework-common",
2464 "netd_aidl_interface-V3-java",
2465 "netlink-client",
2466 "networkstack-aidl-interfaces-java",
2467 "tethering-aidl-interfaces-java",
2468 "TetheringApiCurrentLib",
2469 }
2470 //
2471 // Module separator
2472 //
2473 m["com.android.wifi"] = []string{
2474 "PlatformProperties",
2475 "android.hardware.wifi-V1.0-java",
2476 "android.hardware.wifi-V1.0-java-constants",
2477 "android.hardware.wifi-V1.1-java",
2478 "android.hardware.wifi-V1.2-java",
2479 "android.hardware.wifi-V1.3-java",
2480 "android.hardware.wifi-V1.4-java",
2481 "android.hardware.wifi.hostapd-V1.0-java",
2482 "android.hardware.wifi.hostapd-V1.1-java",
2483 "android.hardware.wifi.hostapd-V1.2-java",
2484 "android.hardware.wifi.supplicant-V1.0-java",
2485 "android.hardware.wifi.supplicant-V1.1-java",
2486 "android.hardware.wifi.supplicant-V1.2-java",
2487 "android.hardware.wifi.supplicant-V1.3-java",
2488 "android.hidl.base-V1.0-java",
2489 "android.hidl.manager-V1.0-java",
2490 "android.hidl.manager-V1.1-java",
2491 "android.hidl.manager-V1.2-java",
2492 "bouncycastle-unbundled",
2493 "dnsresolver_aidl_interface-V2-java",
2494 "error_prone_annotations",
2495 "framework-wifi-pre-jarjar",
2496 "framework-wifi-util-lib",
2497 "ipmemorystore-aidl-interfaces-V3-java",
2498 "ipmemorystore-aidl-interfaces-java",
2499 "ksoap2",
2500 "libnanohttpd",
2501 "libwifi-jni",
2502 "net-utils-services-common",
2503 "netd_aidl_interface-V2-java",
2504 "netd_aidl_interface-unstable-java",
2505 "netd_event_listener_interface-java",
2506 "netlink-client",
2507 "networkstack-client",
2508 "services.net",
2509 "wifi-lite-protos",
2510 "wifi-nano-protos",
2511 "wifi-service-pre-jarjar",
2512 "wifi-service-resources",
2513 }
2514 //
2515 // Module separator
2516 //
2517 m["com.android.sdkext"] = []string{
2518 "fmtlib_ndk",
2519 "libbase_ndk",
2520 "libprotobuf-cpp-lite-ndk",
2521 }
2522 //
2523 // Module separator
2524 //
2525 m["com.android.os.statsd"] = []string{
2526 "libstatssocket",
2527 }
2528 //
2529 // Module separator
2530 //
2531 m[android.AvailableToAnyApex] = []string{
2532 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
2533 "androidx",
2534 "androidx-constraintlayout_constraintlayout",
2535 "androidx-constraintlayout_constraintlayout-nodeps",
2536 "androidx-constraintlayout_constraintlayout-solver",
2537 "androidx-constraintlayout_constraintlayout-solver-nodeps",
2538 "com.google.android.material_material",
2539 "com.google.android.material_material-nodeps",
2540
2541 "libatomic",
2542 "libclang_rt",
2543 "libgcc_stripped",
2544 "libprofile-clang-extras",
2545 "libprofile-clang-extras_ndk",
2546 "libprofile-extras",
2547 "libprofile-extras_ndk",
2548 "libunwind_llvm",
2549 }
2550 return m
2551}
2552
2553func init() {
2554 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
2555 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
2556}
2557
2558func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
2559 rules := make([]android.Rule, 0, len(modules_packages))
2560 for module_name, module_packages := range modules_packages {
2561 permitted_packages_rule := android.NeverAllow().
2562 BootclasspathJar().
2563 With("apex_available", module_name).
2564 WithMatcher("permitted_packages", android.NotInList(module_packages)).
2565 Because("jars that are part of the " + module_name +
2566 " module may only allow these packages: " + strings.Join(module_packages, ",") +
2567 ". Please jarjar or move code around.")
2568 rules = append(rules, permitted_packages_rule)
2569 }
2570 return rules
2571}
2572
2573// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2574// Adding code to the bootclasspath in new packages will cause issues on module update.
2575func qModulesPackages() map[string][]string {
2576 return map[string][]string{
2577 "com.android.conscrypt": []string{
2578 "android.net.ssl",
2579 "com.android.org.conscrypt",
2580 },
2581 "com.android.media": []string{
2582 "android.media",
2583 },
2584 }
2585}
2586
2587// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2588// Adding code to the bootclasspath in new packages will cause issues on module update.
2589func rModulesPackages() map[string][]string {
2590 return map[string][]string{
2591 "com.android.mediaprovider": []string{
2592 "android.provider",
2593 },
2594 "com.android.permission": []string{
2595 "android.permission",
2596 "android.app.role",
2597 "com.android.permission",
2598 "com.android.role",
2599 },
2600 "com.android.sdkext": []string{
2601 "android.os.ext",
2602 },
2603 "com.android.os.statsd": []string{
2604 "android.app",
2605 "android.os",
2606 "android.util",
2607 "com.android.internal.statsd",
2608 "com.android.server.stats",
2609 },
2610 "com.android.wifi": []string{
2611 "com.android.server.wifi",
2612 "com.android.wifi.x",
2613 "android.hardware.wifi",
2614 "android.net.wifi",
2615 },
2616 "com.android.tethering": []string{
2617 "android.net",
2618 },
2619 }
2620}