Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 17 | // This file contains the module implementations for android_app, android_test, and some more |
| 18 | // related module types, including their override variants. |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 19 | |
| 20 | import ( |
Jiakai Zhang | 4f65a03 | 2023-06-01 15:16:58 +0100 | [diff] [blame] | 21 | "fmt" |
Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 22 | "path/filepath" |
Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 23 | "strings" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 24 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/depset" |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
| 28 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 29 | "android/soong/android" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 30 | "android/soong/cc" |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 31 | "android/soong/dexpreopt" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 32 | "android/soong/tradefed" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 35 | func init() { |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 36 | RegisterAppBuildComponents(android.InitRegistrationContext) |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 37 | pctx.HostBinToolVariable("ModifyAllowlistCmd", "modify_permissions_allowlist") |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 40 | var ( |
| 41 | modifyAllowlist = pctx.AndroidStaticRule("modifyAllowlist", |
| 42 | blueprint.RuleParams{ |
| 43 | Command: "${ModifyAllowlistCmd} $in $packageName $out", |
| 44 | CommandDeps: []string{"${ModifyAllowlistCmd}"}, |
| 45 | }, "packageName") |
| 46 | ) |
| 47 | |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 48 | type FlagsPackages struct { |
| 49 | // Paths to the aconfig dump output text files that are consumed by aapt2 |
| 50 | AconfigTextFiles android.Paths |
| 51 | } |
| 52 | |
| 53 | var FlagsPackagesProvider = blueprint.NewProvider[FlagsPackages]() |
| 54 | |
Yu Liu | 42f6997 | 2024-12-13 22:46:12 +0000 | [diff] [blame] | 55 | type AndroidLibraryInfo struct { |
| 56 | // Empty for now |
| 57 | } |
| 58 | |
| 59 | var AndroidLibraryInfoProvider = blueprint.NewProvider[AndroidLibraryInfo]() |
| 60 | |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 61 | func RegisterAppBuildComponents(ctx android.RegistrationContext) { |
| 62 | ctx.RegisterModuleType("android_app", AndroidAppFactory) |
| 63 | ctx.RegisterModuleType("android_test", AndroidTestFactory) |
| 64 | ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory) |
| 65 | ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory) |
| 66 | ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory) |
| 67 | ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Colin Cross | 99939e9 | 2024-10-01 16:02:46 -0700 | [diff] [blame] | 70 | type AppInfo struct { |
| 71 | // Updatable is set to the value of the updatable property |
| 72 | Updatable bool |
| 73 | |
| 74 | // TestHelperApp is true if the module is a android_test_helper_app |
| 75 | TestHelperApp bool |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 76 | |
| 77 | // EmbeddedJNILibs is the list of paths to JNI libraries that were embedded in the APK. |
| 78 | EmbeddedJNILibs android.Paths |
Colin Cross | 99939e9 | 2024-10-01 16:02:46 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | var AppInfoProvider = blueprint.NewProvider[*AppInfo]() |
| 82 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 83 | // AndroidManifest.xml merging |
| 84 | // package splits |
| 85 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 86 | type appProperties struct { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 87 | // Names of extra android_app_certificate modules to sign the apk with in the form ":module". |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 88 | Additional_certificates []string |
| 89 | |
| 90 | // If set, create package-export.apk, which other packages can |
| 91 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 92 | Export_package_resources *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 93 | |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 94 | // Specifies that this app should be installed to the priv-app directory, |
| 95 | // where the system will grant it additional privileges not available to |
| 96 | // normal apps. |
| 97 | Privileged *bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 98 | |
| 99 | // list of resource labels to generate individual resource packages |
| 100 | Package_splits []string |
Jason Monk | d4122be | 2018-08-10 09:33:36 -0400 | [diff] [blame] | 101 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 102 | // list of native libraries that will be provided in or alongside the resulting jar |
Jihoon Kang | 371a037 | 2024-10-01 16:44:41 +0000 | [diff] [blame] | 103 | Jni_libs proptools.Configurable[[]string] `android:"arch_variant"` |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 104 | |
Colin Cross | 7204cf0 | 2020-05-06 17:51:39 -0700 | [diff] [blame] | 105 | // if true, use JNI libraries that link against platform APIs even if this module sets |
Colin Cross | ee87c60 | 2020-02-19 16:57:15 -0800 | [diff] [blame] | 106 | // sdk_version. |
| 107 | Jni_uses_platform_apis *bool |
| 108 | |
Colin Cross | 7204cf0 | 2020-05-06 17:51:39 -0700 | [diff] [blame] | 109 | // if true, use JNI libraries that link against SDK APIs even if this module does not set |
| 110 | // sdk_version. |
| 111 | Jni_uses_sdk_apis *bool |
| 112 | |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 113 | // STL library to use for JNI libraries. |
| 114 | Stl *string `android:"arch_variant"` |
| 115 | |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 116 | // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 117 | // flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless |
| 118 | // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for |
| 119 | // android_app modules that are embedded to APEXes, defaults to false for other module types where the native |
| 120 | // libraries are generally preinstalled outside the APK. |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 121 | Use_embedded_native_libs *bool |
Colin Cross | 46abdad | 2019-02-07 13:07:08 -0800 | [diff] [blame] | 122 | |
| 123 | // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that |
| 124 | // they are used from inside the APK at runtime. |
| 125 | Use_embedded_dex *bool |
Colin Cross | 47fa9d3 | 2019-03-26 10:51:39 -0700 | [diff] [blame] | 126 | |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 127 | // Forces native libraries to always be packaged into the APK, |
| 128 | // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed. |
| 129 | // True for android_test* modules. |
| 130 | AlwaysPackageNativeLibs bool `blueprint:"mutated"` |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 131 | |
| 132 | // If set, find and merge all NOTICE files that this module and its dependencies have and store |
| 133 | // it in the APK as an asset. |
| 134 | Embed_notices *bool |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 135 | |
| 136 | // cc.Coverage related properties |
| 137 | PreventInstall bool `blueprint:"mutated"` |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 138 | IsCoverageVariant bool `blueprint:"mutated"` |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 139 | |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 140 | // It can be set to test the behaviour of default target sdk version. |
| 141 | // Only required when updatable: false. It is an error if updatable: true and this is false. |
| 142 | Enforce_default_target_sdk_version *bool |
| 143 | |
| 144 | // If set, the targetSdkVersion for the target is set to the latest default API level. |
| 145 | // This would be by default false, unless updatable: true or |
| 146 | // enforce_default_target_sdk_version: true in which case this defaults to true. |
| 147 | EnforceDefaultTargetSdkVersion bool `blueprint:"mutated"` |
| 148 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 149 | // Whether this app is considered mainline updatable or not. When set to true, this will enforce |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 150 | // additional rules to make sure an app can safely be updated. Default is false. |
| 151 | // Prefer using other specific properties if build behaviour must be changed; avoid using this |
| 152 | // flag for anything but neverallow rules (unless the behaviour change is invisible to owners). |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 153 | Updatable *bool |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 154 | |
| 155 | // Specifies the file that contains the allowlist for this app. |
| 156 | Privapp_allowlist *string `android:"path"` |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 157 | |
| 158 | // If set, create an RRO package which contains only resources having PRODUCT_CHARACTERISTICS |
| 159 | // and install the RRO package to /product partition, instead of passing --product argument |
| 160 | // to aapt2. Default is false. |
| 161 | // Setting this will make this APK identical to all targets, regardless of |
| 162 | // PRODUCT_CHARACTERISTICS. |
| 163 | Generate_product_characteristics_rro *bool |
| 164 | |
| 165 | ProductCharacteristicsRROPackageName *string `blueprint:"mutated"` |
| 166 | ProductCharacteristicsRROManifestModuleName *string `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 169 | // android_app properties that can be overridden by override_android_app |
| 170 | type overridableAppProperties struct { |
| 171 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 172 | // or an android_app_certificate module name in the form ":module". |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 173 | Certificate proptools.Configurable[string] `android:"replace_instead_of_append"` |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 174 | |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 175 | // Name of the signing certificate lineage file or filegroup module. |
| 176 | Lineage *string `android:"path"` |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 177 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 178 | // For overriding the --rotation-min-sdk-version property of apksig |
| 179 | RotationMinSdkVersion *string |
| 180 | |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 181 | // the package name of this app. The package name in the manifest file is used if one was not given. |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 182 | Package_name proptools.Configurable[string] |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 183 | |
| 184 | // the logging parent of this app. |
| 185 | Logging_parent *string |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 186 | |
| 187 | // Whether to rename the package in resources to the override name rather than the base name. Defaults to true. |
| 188 | Rename_resources_package *bool |
zhidou | 198f589 | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 189 | |
| 190 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 191 | // (in Make or Soong). |
| 192 | // This does not completely prevent installation of the overridden binaries, but if both |
| 193 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 194 | // from PRODUCT_PACKAGES. |
| 195 | Overrides []string |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 198 | type AndroidApp struct { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 199 | Library |
| 200 | aapt |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 201 | android.OverridableModuleBase |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 202 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 203 | certificate Certificate |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 204 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 205 | appProperties appProperties |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 206 | |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 207 | overridableAppProperties overridableAppProperties |
| 208 | |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 209 | jniLibs []jniLib |
| 210 | installPathForJNISymbols android.Path |
| 211 | embeddedJniLibs bool |
| 212 | jniCoverageOutputs android.Paths |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 213 | |
| 214 | bundleFile android.Path |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 215 | |
| 216 | // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES. |
| 217 | installApkName string |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 218 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 219 | installDir android.InstallPath |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 220 | |
Jaewoong Jung | 7dd4ae2 | 2019-09-27 17:13:15 -0700 | [diff] [blame] | 221 | onDeviceDir string |
| 222 | |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 223 | additionalAaptFlags []string |
Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame] | 224 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 225 | overriddenManifestPackageName string |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 226 | |
| 227 | android.ApexBundleDepsInfo |
Matt Banda | 8c80126 | 2022-04-01 17:48:31 +0000 | [diff] [blame] | 228 | |
| 229 | javaApiUsedByOutputFile android.ModuleOutPath |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 230 | |
| 231 | privAppAllowlist android.OptionalPath |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 232 | |
| 233 | requiredModuleNames []string |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 236 | func (a *AndroidApp) IsInstallable() bool { |
| 237 | return Bool(a.properties.Installable) |
| 238 | } |
| 239 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 240 | func (a *AndroidApp) ResourcesNodeDepSet() depset.DepSet[*resourcesNode] { |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 241 | return a.aapt.resourcesNodesDepSet |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 244 | func (a *AndroidApp) OutputFile() android.Path { |
| 245 | return a.outputFile |
| 246 | } |
| 247 | |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 248 | func (a *AndroidApp) Certificate() Certificate { |
| 249 | return a.certificate |
| 250 | } |
| 251 | |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 252 | func (a *AndroidApp) JniCoverageOutputs() android.Paths { |
| 253 | return a.jniCoverageOutputs |
| 254 | } |
| 255 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 256 | func (a *AndroidApp) PrivAppAllowlist() android.OptionalPath { |
| 257 | return a.privAppAllowlist |
| 258 | } |
| 259 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 260 | var _ AndroidLibraryDependency = (*AndroidApp)(nil) |
| 261 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 262 | type Certificate struct { |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 263 | Pem, Key android.Path |
| 264 | presigned bool |
| 265 | } |
| 266 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 267 | var PresignedCertificate = Certificate{presigned: true} |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 268 | |
| 269 | func (c Certificate) AndroidMkString() string { |
| 270 | if c.presigned { |
| 271 | return "PRESIGNED" |
| 272 | } else { |
| 273 | return c.Pem.String() |
| 274 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 277 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 278 | if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion(ctx).Specified() { |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 279 | ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared") |
| 280 | } |
| 281 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 282 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 283 | a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs()) |
| 284 | a.Module.deps(ctx) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 285 | if sdkDep.hasFrameworkLibs() { |
| 286 | a.aapt.deps(ctx, sdkDep) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 287 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 288 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 289 | usesSDK := a.SdkVersion(ctx).Specified() && a.SdkVersion(ctx).Kind != android.SdkCorePlatform |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 290 | |
| 291 | if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) { |
| 292 | ctx.PropertyErrorf("jni_uses_sdk_apis", |
| 293 | "can only be set for modules that do not set sdk_version") |
| 294 | } else if !usesSDK && Bool(a.appProperties.Jni_uses_platform_apis) { |
| 295 | ctx.PropertyErrorf("jni_uses_platform_apis", |
| 296 | "can only be set for modules that set sdk_version") |
| 297 | } |
| 298 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 299 | for _, jniTarget := range ctx.MultiTargets() { |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 300 | variation := append(jniTarget.Variations(), |
| 301 | blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 302 | |
Jiyong Park | 92d8404 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 303 | // Test whether to use the SDK variant or the non-SDK variant of JNI dependencies. |
| 304 | // Many factors are considered here. |
| 305 | // 1. Basically, the selection follows whether the app has sdk_version set or not. |
| 306 | jniUsesSdkVariant := usesSDK |
| 307 | // 2. However, jni_uses_platform_apis and jni_uses_sdk_apis can override it |
| 308 | if Bool(a.appProperties.Jni_uses_sdk_apis) { |
| 309 | jniUsesSdkVariant = true |
| 310 | } |
| 311 | if Bool(a.appProperties.Jni_uses_platform_apis) { |
| 312 | jniUsesSdkVariant = false |
| 313 | } |
| 314 | // 3. Then the use of SDK variant is again prohibited for the following cases: |
| 315 | // 3.1. the app is shipped on unbundled partitions like vendor. Since the entire |
| 316 | // partition (not only the app) is considered unbudled, there's no need to use the |
| 317 | // SDK variant. |
| 318 | // 3.2. the app doesn't support embedding the JNI libs |
| 319 | if a.RequiresStableAPIs(ctx) || !a.shouldEmbedJnis(ctx) { |
| 320 | jniUsesSdkVariant = false |
| 321 | } |
| 322 | if jniUsesSdkVariant { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 323 | variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"}) |
| 324 | } |
Jiyong Park | 92d8404 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 325 | |
| 326 | // Use the installable dep tag when the JNIs are not embedded |
| 327 | var tag dependencyTag |
| 328 | if a.shouldEmbedJnis(ctx) { |
| 329 | tag = jniLibTag |
| 330 | } else { |
| 331 | tag = jniInstallTag |
| 332 | } |
Jihoon Kang | 371a037 | 2024-10-01 16:44:41 +0000 | [diff] [blame] | 333 | ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs.GetOrDefault(ctx, nil)...) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 334 | } |
Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 335 | for _, aconfig_declaration := range a.aaptProperties.Flags_packages { |
| 336 | ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) |
| 337 | } |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 338 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 339 | |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 340 | func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 341 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 342 | if cert != "" { |
| 343 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 344 | } |
| 345 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 346 | if a.appProperties.Privapp_allowlist != nil && !Bool(a.appProperties.Privileged) { |
Anton Hansson | e3f31cf | 2023-06-03 08:53:47 +0000 | [diff] [blame] | 347 | // There are a few uids that are explicitly considered privileged regardless of their |
| 348 | // app's location. Bluetooth is one such app. It should arguably be moved to priv-app, |
| 349 | // but for now, allow it not to be in priv-app. |
| 350 | privilegedBecauseOfUid := ctx.ModuleName() == "Bluetooth" |
| 351 | if !privilegedBecauseOfUid { |
| 352 | ctx.PropertyErrorf("privapp_allowlist", "privileged must be set in order to use privapp_allowlist (with a few exceptions)") |
| 353 | } |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 356 | for _, cert := range a.appProperties.Additional_certificates { |
| 357 | cert = android.SrcIsModule(cert) |
| 358 | if cert != "" { |
| 359 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 360 | } else { |
| 361 | ctx.PropertyErrorf("additional_certificates", |
| 362 | `must be names of android_app_certificate modules in the form ":module"`) |
| 363 | } |
| 364 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Spandan Das | b041087 | 2024-06-25 03:30:03 +0000 | [diff] [blame] | 367 | // TODO(b/156476221): Remove this allowlist |
| 368 | var ( |
| 369 | missingMinSdkVersionMtsAllowlist = []string{ |
| 370 | "CellBroadcastReceiverGoogleUnitTests", |
| 371 | "CellBroadcastReceiverUnitTests", |
| 372 | "CtsBatterySavingTestCases", |
| 373 | "CtsDeviceAndProfileOwnerApp23", |
| 374 | "CtsDeviceAndProfileOwnerApp30", |
| 375 | "CtsIntentSenderApp", |
| 376 | "CtsJobSchedulerTestCases", |
| 377 | "CtsMimeMapTestCases", |
| 378 | "CtsTareTestCases", |
| 379 | "LibStatsPullTests", |
| 380 | "MediaProviderClientTests", |
| 381 | "TeleServiceTests", |
| 382 | "TestExternalImsServiceApp", |
| 383 | "TestSmsRetrieverApp", |
| 384 | "TetheringPrivilegedTests", |
| 385 | } |
| 386 | ) |
| 387 | |
| 388 | func checkMinSdkVersionMts(ctx android.ModuleContext, minSdkVersion android.ApiLevel) { |
| 389 | if includedInMts(ctx.Module()) && !minSdkVersion.Specified() && !android.InList(ctx.ModuleName(), missingMinSdkVersionMtsAllowlist) { |
| 390 | ctx.PropertyErrorf("min_sdk_version", "min_sdk_version is a required property for tests included in MTS") |
| 391 | } |
| 392 | } |
| 393 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 394 | func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | b041087 | 2024-06-25 03:30:03 +0000 | [diff] [blame] | 395 | checkMinSdkVersionMts(ctx, a.MinSdkVersion(ctx)) |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 396 | applicationId := a.appTestHelperAppProperties.Manifest_values.ApplicationId |
| 397 | if applicationId != nil { |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 398 | packageName := a.overridableAppProperties.Package_name.Get(ctx) |
| 399 | if packageName.IsPresent() { |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 400 | ctx.PropertyErrorf("manifest_values.applicationId", "property is not supported when property package_name is set.") |
| 401 | } |
| 402 | a.aapt.manifestValues.applicationId = *applicationId |
| 403 | } |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 404 | a.generateAndroidBuildActions(ctx) |
Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 405 | android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ |
| 406 | TestOnly: true, |
| 407 | }) |
Colin Cross | 99939e9 | 2024-10-01 16:02:46 -0700 | [diff] [blame] | 408 | android.SetProvider(ctx, AppInfoProvider, &AppInfo{ |
| 409 | Updatable: Bool(a.appProperties.Updatable), |
| 410 | TestHelperApp: true, |
| 411 | }) |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 412 | } |
| 413 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 414 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 415 | a.checkAppSdkVersions(ctx) |
Jiyong Park | 970c524 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 416 | a.checkEmbedJnis(ctx) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 417 | a.generateAndroidBuildActions(ctx) |
Matt Banda | 8c80126 | 2022-04-01 17:48:31 +0000 | [diff] [blame] | 418 | a.generateJavaUsedByApex(ctx) |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 419 | |
| 420 | var embeddedJniLibs []android.Path |
| 421 | |
| 422 | if a.embeddedJniLibs { |
| 423 | for _, jni := range a.jniLibs { |
| 424 | embeddedJniLibs = append(embeddedJniLibs, jni.path) |
| 425 | } |
| 426 | } |
Colin Cross | 99939e9 | 2024-10-01 16:02:46 -0700 | [diff] [blame] | 427 | android.SetProvider(ctx, AppInfoProvider, &AppInfo{ |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 428 | Updatable: Bool(a.appProperties.Updatable), |
| 429 | TestHelperApp: false, |
| 430 | EmbeddedJNILibs: embeddedJniLibs, |
Colin Cross | 99939e9 | 2024-10-01 16:02:46 -0700 | [diff] [blame] | 431 | }) |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 432 | |
Yu Liu | 42f6997 | 2024-12-13 22:46:12 +0000 | [diff] [blame] | 433 | android.SetProvider(ctx, AndroidLibraryInfoProvider, AndroidLibraryInfo{}) |
| 434 | |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 435 | a.requiredModuleNames = a.getRequiredModuleNames(ctx) |
| 436 | } |
| 437 | |
| 438 | func (a *AndroidApp) getRequiredModuleNames(ctx android.ModuleContext) []string { |
| 439 | var required []string |
| 440 | if proptools.Bool(a.appProperties.Generate_product_characteristics_rro) { |
| 441 | required = []string{a.productCharacteristicsRROPackageName()} |
| 442 | } |
| 443 | // Install the vendor overlay variant if this app is installed. |
| 444 | if len(filterRRO(a.rroDirsDepSet, device)) > 0 { |
| 445 | required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "vendor")) |
| 446 | } |
| 447 | // Install the product overlay variant if this app is installed. |
| 448 | if len(filterRRO(a.rroDirsDepSet, product)) > 0 { |
| 449 | required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "product")) |
| 450 | } |
| 451 | return required |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 454 | func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 455 | if a.Updatable() { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 456 | if !a.SdkVersion(ctx).Stable() { |
| 457 | ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx)) |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 458 | } |
Spandan Das | b9c5835 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 459 | if String(a.overridableProperties.Min_sdk_version) == "" { |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 460 | ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.") |
| 461 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 462 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 463 | if minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx); err == nil { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 464 | a.checkJniLibsSdkVersion(ctx, minSdkVersion) |
satayev | b3fd411 | 2021-12-02 13:59:35 +0000 | [diff] [blame] | 465 | android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 466 | } else { |
| 467 | ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) |
| 468 | } |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 469 | |
| 470 | if !BoolDefault(a.appProperties.Enforce_default_target_sdk_version, true) { |
| 471 | ctx.PropertyErrorf("enforce_default_target_sdk_version", "Updatable apps must enforce default target sdk version") |
| 472 | } |
| 473 | // TODO(b/227460469) after all the modules removes the target sdk version, throw an error if the target sdk version is explicitly set. |
| 474 | if a.deviceProperties.Target_sdk_version == nil { |
| 475 | a.SetEnforceDefaultTargetSdkVersion(true) |
| 476 | } |
| 477 | } |
| 478 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 479 | a.checkPlatformAPI(ctx) |
| 480 | a.checkSdkVersions(ctx) |
| 481 | } |
| 482 | |
Jiyong Park | 970c524 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 483 | // Ensures that use_embedded_native_libs are set for apk-in-apex |
| 484 | func (a *AndroidApp) checkEmbedJnis(ctx android.BaseModuleContext) { |
| 485 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 486 | apkInApex := !apexInfo.IsForPlatform() |
Jihoon Kang | 371a037 | 2024-10-01 16:44:41 +0000 | [diff] [blame] | 487 | hasJnis := len(a.appProperties.Jni_libs.GetOrDefault(ctx, nil)) > 0 |
Jiyong Park | 970c524 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 488 | |
| 489 | if apkInApex && hasJnis && !Bool(a.appProperties.Use_embedded_native_libs) { |
| 490 | ctx.ModuleErrorf("APK in APEX should have use_embedded_native_libs: true") |
| 491 | } |
| 492 | } |
| 493 | |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 494 | // If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it. |
| 495 | // This check is enforced for "updatable" APKs (including APK-in-APEX). |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 496 | func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion android.ApiLevel) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 497 | // It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType() |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame^] | 498 | ctx.VisitDirectDepsProxy(func(m android.ModuleProxy) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 499 | if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) { |
| 500 | return |
| 501 | } |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame^] | 502 | if _, ok := android.OtherModuleProvider(ctx, m, cc.CcInfoProvider); !ok { |
| 503 | panic(fmt.Errorf("jni dependency is not a cc module: %v", m)) |
| 504 | } |
| 505 | commonInfo, ok := android.OtherModuleProvider(ctx, m, android.CommonModuleInfoKey) |
| 506 | if !ok { |
| 507 | panic(fmt.Errorf("jni dependency doesn't have CommonModuleInfo provider: %v", m)) |
| 508 | } |
Jooyung Han | 652d5b3 | 2020-05-20 17:12:13 +0900 | [diff] [blame] | 509 | // The domain of cc.sdk_version is "current" and <number> |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 510 | // We can rely on android.SdkSpec to convert it to <number> so that "current" is |
| 511 | // handled properly regardless of sdk finalization. |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame^] | 512 | jniSdkVersion, err := android.SdkSpecFrom(ctx, commonInfo.MinSdkVersion).EffectiveVersion(ctx) |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 513 | if err != nil || minSdkVersion.LessThan(jniSdkVersion) { |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame^] | 514 | ctx.OtherModuleErrorf(m, "min_sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)", |
| 515 | commonInfo.MinSdkVersion, minSdkVersion, ctx.ModuleName()) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 516 | return |
| 517 | } |
| 518 | |
| 519 | }) |
| 520 | } |
| 521 | |
Sasha Smundak | 6ad7725 | 2019-05-01 13:16:22 -0700 | [diff] [blame] | 522 | // Returns true if the native libraries should be stored in the APK uncompressed and the |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 523 | // extractNativeLibs application flag should be set to false in the manifest. |
Sasha Smundak | 6ad7725 | 2019-05-01 13:16:22 -0700 | [diff] [blame] | 524 | func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 525 | minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx) |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 526 | if err != nil { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 527 | ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(ctx), err) |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 530 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 531 | return (minSdkVersion.FinalOrFutureInt() >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) || |
| 532 | !apexInfo.IsForPlatform() |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 535 | // Returns whether this module should have the dex file stored uncompressed in the APK. |
| 536 | func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { |
Colin Cross | 46abdad | 2019-02-07 13:07:08 -0800 | [diff] [blame] | 537 | if Bool(a.appProperties.Use_embedded_dex) { |
| 538 | return true |
| 539 | } |
| 540 | |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 541 | // Uncompress dex in APKs of privileged apps (even for unbundled builds, they may |
| 542 | // be preinstalled as prebuilts). |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 543 | if ctx.Config().UncompressPrivAppDex() && a.Privileged() { |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 544 | return true |
| 545 | } |
| 546 | |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 547 | if ctx.Config().UnbundledBuild() { |
| 548 | return false |
| 549 | } |
| 550 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 551 | return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 554 | func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 555 | return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) || |
Jiyong Park | 970c524 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 556 | Bool(a.appProperties.Updatable) || |
| 557 | a.appProperties.AlwaysPackageNativeLibs |
Jiyong Park | ef5511f | 2024-05-08 09:54:22 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 560 | func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string { |
| 561 | aaptFlags := []string{"--rename-manifest-package " + packageName} |
| 562 | if renameResourcesPackage { |
| 563 | // Required to rename the package name in the resources table. |
| 564 | aaptFlags = append(aaptFlags, "--rename-resources-package "+packageName) |
| 565 | } |
| 566 | return aaptFlags |
| 567 | } |
| 568 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 569 | func (a *AndroidApp) OverriddenManifestPackageName() string { |
| 570 | return a.overriddenManifestPackageName |
| 571 | } |
| 572 | |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 573 | func (a *AndroidApp) renameResourcesPackage() bool { |
| 574 | return proptools.BoolDefault(a.overridableAppProperties.Rename_resources_package, true) |
| 575 | } |
| 576 | |
Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 577 | func getAconfigFilePaths(ctx android.ModuleContext) (aconfigTextFilePaths android.Paths) { |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 578 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 579 | tag := ctx.OtherModuleDependencyTag(dep) |
| 580 | switch tag { |
| 581 | case staticLibTag: |
| 582 | if flagPackages, ok := android.OtherModuleProvider(ctx, dep, FlagsPackagesProvider); ok { |
| 583 | aconfigTextFilePaths = append(aconfigTextFilePaths, flagPackages.AconfigTextFiles...) |
| 584 | } |
| 585 | |
| 586 | case aconfigDeclarationTag: |
| 587 | if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok { |
| 588 | aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath) |
| 589 | } else { |
| 590 | ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+ |
| 591 | "flags_packages property, but %s is not aconfig_declarations module type", |
| 592 | dep.Name(), |
| 593 | ) |
| 594 | } |
Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 595 | } |
| 596 | }) |
| 597 | |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 598 | return android.FirstUniquePaths(aconfigTextFilePaths) |
Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 601 | func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { |
Lorenzo Colitti | fa9b3f3 | 2021-03-30 10:38:26 +0900 | [diff] [blame] | 602 | usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis) |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 603 | if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule { |
Lorenzo Colitti | fa9b3f3 | 2021-03-30 10:38:26 +0900 | [diff] [blame] | 604 | usePlatformAPI = true |
| 605 | } |
| 606 | a.aapt.usesNonSdkApis = usePlatformAPI |
David Brazdil | d25060a | 2019-02-18 18:24:16 +0000 | [diff] [blame] | 607 | |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 608 | // Ask manifest_fixer to add or update the application element indicating this app has no code. |
| 609 | a.aapt.hasNoCode = !a.hasCode(ctx) |
| 610 | |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 611 | aaptLinkFlags := []string{} |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 612 | |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 613 | // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided. |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 614 | autogenerateRRO := proptools.Bool(a.appProperties.Generate_product_characteristics_rro) |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 615 | hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product") |
Inseob Kim | 10af6ed | 2024-02-13 12:56:46 +0900 | [diff] [blame] | 616 | characteristics := ctx.Config().ProductAAPTCharacteristics() |
| 617 | if !autogenerateRRO && !hasProduct && len(characteristics) > 0 && characteristics != "default" { |
| 618 | aaptLinkFlags = append(aaptLinkFlags, "--product", characteristics) |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 621 | if !Bool(a.aaptProperties.Aapt_include_all_resources) { |
| 622 | // Product AAPT config |
| 623 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 624 | aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig) |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 625 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 626 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 627 | // Product AAPT preferred config |
| 628 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 629 | aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 630 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 633 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 634 | packageNameProp := a.overridableAppProperties.Package_name.Get(ctx) |
| 635 | if overridden || packageNameProp.IsPresent() { |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 636 | // The product override variable has a priority over the package_name property. |
| 637 | if !overridden { |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 638 | manifestPackageName = packageNameProp.Get() |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 639 | } |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 640 | aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName, a.renameResourcesPackage())...) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 641 | a.overriddenManifestPackageName = manifestPackageName |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 642 | } |
| 643 | |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 644 | aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...) |
| 645 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 646 | a.aapt.splitNames = a.appProperties.Package_splits |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 647 | a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) |
Alexei Nicoara | 69cf0f3 | 2022-07-27 14:59:18 +0100 | [diff] [blame] | 648 | if a.Updatable() { |
Alyssa Ketpreechasawat | ee8b44e | 2024-07-04 10:45:04 +0000 | [diff] [blame] | 649 | if override := ctx.Config().Getenv("OVERRIDE_APEX_MANIFEST_DEFAULT_VERSION"); override != "" { |
| 650 | a.aapt.defaultManifestVersion = override |
| 651 | } else { |
Alyssa Ketpreechasawat | 3a6eced | 2024-08-22 15:09:16 +0000 | [diff] [blame] | 652 | a.aapt.defaultManifestVersion = ctx.Config().ReleaseDefaultUpdatableModuleVersion() |
Alyssa Ketpreechasawat | ee8b44e | 2024-07-04 10:45:04 +0000 | [diff] [blame] | 653 | } |
Alexei Nicoara | 69cf0f3 | 2022-07-27 14:59:18 +0100 | [diff] [blame] | 654 | } |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 655 | |
Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 656 | // Use non final ids if we are doing optimized shrinking and are using R8. |
Rico Wind | 936754c | 2024-05-07 09:08:31 +0200 | [diff] [blame] | 657 | nonFinalIds := a.dexProperties.optimizedResourceShrinkingEnabled(ctx) && a.dexer.effectiveOptimizeEnabled() |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 658 | |
| 659 | aconfigTextFilePaths := getAconfigFilePaths(ctx) |
| 660 | |
Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 661 | a.aapt.buildActions(ctx, |
| 662 | aaptBuildActionOptions{ |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 663 | sdkContext: android.SdkContext(a), |
| 664 | classLoaderContexts: a.classLoaderContexts, |
| 665 | excludedLibs: a.usesLibraryProperties.Exclude_uses_libs, |
| 666 | enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(), |
Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 667 | forceNonFinalResourceIDs: nonFinalIds, |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 668 | extraLinkFlags: aaptLinkFlags, |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 669 | aconfigTextFiles: aconfigTextFilePaths, |
Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 670 | usesLibrary: &a.usesLibrary, |
Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 671 | }, |
| 672 | ) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 673 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 674 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 675 | a.properties.Manifest = nil |
Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 676 | |
| 677 | android.SetProvider(ctx, FlagsPackagesProvider, FlagsPackages{ |
| 678 | AconfigTextFiles: aconfigTextFilePaths, |
| 679 | }) |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 680 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 681 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 682 | func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) { |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 683 | var staticLibProguardFlagFiles android.Paths |
| 684 | ctx.VisitDirectDeps(func(m android.Module) { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 685 | depProguardInfo, _ := android.OtherModuleProvider(ctx, m, ProguardSpecInfoProvider) |
Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 686 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, depProguardInfo.UnconditionallyExportedProguardFlags.ToList()...) |
| 687 | if ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 688 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, depProguardInfo.ProguardFlagsFiles.ToList()...) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 689 | } |
| 690 | }) |
| 691 | |
| 692 | staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles) |
| 693 | |
Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 694 | a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, staticLibProguardFlagFiles...) |
Rico Wind | 936754c | 2024-05-07 09:08:31 +0200 | [diff] [blame] | 695 | if !(a.dexProperties.optimizedResourceShrinkingEnabled(ctx)) { |
Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 696 | // When using the optimized shrinking the R8 enqueuer will traverse the xml files that become |
| 697 | // live for code references and (transitively) mark these as live. |
| 698 | // In this case we explicitly don't wan't the aapt2 generated keep files (which would keep the now |
| 699 | // dead code alive) |
| 700 | a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, a.proguardOptionsFile) |
| 701 | } |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 702 | } |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 703 | |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 704 | func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 705 | var installDir string |
| 706 | if ctx.ModuleName() == "framework-res" { |
| 707 | // framework-res.apk is installed as system/framework/framework-res.apk |
| 708 | installDir = "framework" |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 709 | } else if a.Privileged() { |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 710 | installDir = filepath.Join("priv-app", a.installApkName) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 711 | } else { |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 712 | installDir = filepath.Join("app", a.installApkName) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 713 | } |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 714 | |
| 715 | return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") |
| 716 | } |
| 717 | |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 718 | func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) (android.Path, android.Path) { |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 719 | a.dexpreopter.installPath = a.installPath(ctx) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 720 | a.dexpreopter.isApp = true |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 721 | if a.dexProperties.Uncompress_dex == nil { |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 722 | // If the value was not force-set by the user, use reasonable default based on the module. |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 723 | a.dexProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx)) |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 724 | } |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 725 | a.dexpreopter.uncompressedDex = *a.dexProperties.Uncompress_dex |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 726 | a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries(ctx) |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 727 | a.dexpreopter.classLoaderContexts = a.classLoaderContexts |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 728 | a.dexpreopter.manifestFile = a.mergedManifestFile |
Colin Cross | fa9bfcd | 2021-11-10 16:42:38 -0800 | [diff] [blame] | 729 | a.dexpreopter.preventInstall = a.appProperties.PreventInstall |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 730 | |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 731 | var packageResources = a.exportPackage |
| 732 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 733 | if ctx.ModuleName() != "framework-res" { |
Rico Wind | 936754c | 2024-05-07 09:08:31 +0200 | [diff] [blame] | 734 | if a.dexProperties.resourceShrinkingEnabled(ctx) { |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 735 | protoFile := android.PathForModuleOut(ctx, packageResources.Base()+".proto.apk") |
| 736 | aapt2Convert(ctx, protoFile, packageResources, "proto") |
| 737 | a.dexer.resourcesInput = android.OptionalPathForPath(protoFile) |
| 738 | } |
| 739 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 740 | var extraSrcJars android.Paths |
| 741 | var extraClasspathJars android.Paths |
| 742 | var extraCombinedJars android.Paths |
Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 743 | if a.useResourceProcessorBusyBox(ctx) { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 744 | // When building an app with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox has already |
| 745 | // created R.class files that provide IDs for resources in busybox/R.jar. Pass that file in the |
| 746 | // classpath when compiling everything else, and add it to the final classes jar. |
| 747 | extraClasspathJars = android.Paths{a.aapt.rJar} |
| 748 | extraCombinedJars = android.Paths{a.aapt.rJar} |
| 749 | } else { |
| 750 | // When building an app without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing |
| 751 | // R.java files for the app's package and the packages from all transitive static android_library |
| 752 | // dependencies. Compile the srcjar alongside the rest of the sources. |
| 753 | extraSrcJars = android.Paths{a.aapt.aaptSrcJar} |
| 754 | } |
| 755 | |
Colin Cross | fdaa672 | 2024-08-23 11:58:08 -0700 | [diff] [blame] | 756 | a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars, nil) |
Rico Wind | 936754c | 2024-05-07 09:08:31 +0200 | [diff] [blame] | 757 | if a.dexProperties.resourceShrinkingEnabled(ctx) { |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 758 | binaryResources := android.PathForModuleOut(ctx, packageResources.Base()+".binary.out.apk") |
| 759 | aapt2Convert(ctx, binaryResources, a.dexer.resourcesOutput.Path(), "binary") |
| 760 | packageResources = binaryResources |
| 761 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 762 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 763 | |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 764 | return a.dexJarFile.PathOrNil(), packageResources |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 765 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 766 | |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 767 | func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, prebuiltJniPackages android.Paths, ctx android.ModuleContext) android.WritablePath { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 768 | var jniJarFile android.WritablePath |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 769 | if len(jniLibs) > 0 || len(prebuiltJniPackages) > 0 { |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 770 | a.jniLibs = jniLibs |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 771 | if a.shouldEmbedJnis(ctx) { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 772 | jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 773 | a.installPathForJNISymbols = a.installPath(ctx) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 774 | TransformJniLibsToJar(ctx, jniJarFile, jniLibs, prebuiltJniPackages, a.useEmbeddedNativeLibs(ctx)) |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 775 | for _, jni := range jniLibs { |
| 776 | if jni.coverageFile.Valid() { |
Jaewoong Jung | 46984ee | 2020-04-07 13:07:55 -0700 | [diff] [blame] | 777 | // Only collect coverage for the first target arch if this is a multilib target. |
| 778 | // TODO(jungjw): Ideally, we want to collect both reports, but that would cause coverage |
| 779 | // data file path collisions since the current coverage file path format doesn't contain |
| 780 | // arch-related strings. This is fine for now though; the code coverage team doesn't use |
| 781 | // multi-arch targets such as test_suite_* for coverage collections yet. |
| 782 | // |
| 783 | // Work with the team to come up with a new format that handles multilib modules properly |
| 784 | // and change this. |
| 785 | if len(ctx.Config().Targets[android.Android]) == 1 || |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 786 | ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType == jni.target.Arch.ArchType { |
Jaewoong Jung | 46984ee | 2020-04-07 13:07:55 -0700 | [diff] [blame] | 787 | a.jniCoverageOutputs = append(a.jniCoverageOutputs, jni.coverageFile.Path()) |
| 788 | } |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 791 | a.embeddedJniLibs = true |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 792 | } |
| 793 | } |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 794 | return jniJarFile |
| 795 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 796 | |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 797 | func (a *AndroidApp) JNISymbolsInstalls(installPath string) android.RuleBuilderInstalls { |
| 798 | var jniSymbols android.RuleBuilderInstalls |
| 799 | for _, jniLib := range a.jniLibs { |
| 800 | if jniLib.unstrippedFile != nil { |
| 801 | jniSymbols = append(jniSymbols, android.RuleBuilderInstall{ |
| 802 | From: jniLib.unstrippedFile, |
| 803 | To: filepath.Join(installPath, targetToJniDir(jniLib.target), jniLib.unstrippedFile.Base()), |
| 804 | }) |
| 805 | } |
| 806 | } |
| 807 | return jniSymbols |
| 808 | } |
| 809 | |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 810 | // Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it |
| 811 | // isn't a cert module reference. Also checks and enforces system cert restriction if applicable. |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 812 | func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate, |
| 813 | ctx android.ModuleContext) (mainCertificate Certificate, allCertificates []Certificate) { |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 814 | if android.SrcIsModule(certPropValue) == "" { |
| 815 | var mainCert Certificate |
| 816 | if certPropValue != "" { |
| 817 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 818 | mainCert = Certificate{ |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 819 | Pem: defaultDir.Join(ctx, certPropValue+".x509.pem"), |
| 820 | Key: defaultDir.Join(ctx, certPropValue+".pk8"), |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 821 | } |
| 822 | } else { |
| 823 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 824 | mainCert = Certificate{ |
| 825 | Pem: pem, |
| 826 | Key: key, |
| 827 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 828 | } |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 829 | certificates = append([]Certificate{mainCert}, certificates...) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 832 | if len(certificates) > 0 { |
| 833 | mainCertificate = certificates[0] |
| 834 | } else { |
| 835 | // This can be reached with an empty certificate list if AllowMissingDependencies is set |
| 836 | // and the certificate property for this module is a module reference to a missing module. |
| 837 | if !ctx.Config().AllowMissingDependencies() && len(ctx.GetMissingDependencies()) > 0 { |
| 838 | panic("Should only get here if AllowMissingDependencies set and there are missing dependencies") |
| 839 | } |
| 840 | // Set a certificate to avoid panics later when accessing it. |
| 841 | mainCertificate = Certificate{ |
| 842 | Key: android.PathForModuleOut(ctx, "missing.pk8"), |
Colin Cross | a54f4b5 | 2022-11-21 04:35:53 +0000 | [diff] [blame] | 843 | Pem: android.PathForModuleOut(ctx, "missing.x509.pem"), |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
Zyan Wu | b7550aa | 2023-05-18 15:46:31 +0800 | [diff] [blame] | 847 | if !m.Platform() { |
| 848 | certPath := mainCertificate.Pem.String() |
| 849 | systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String() |
| 850 | if strings.HasPrefix(certPath, systemCertPath) { |
| 851 | enforceSystemCert := ctx.Config().EnforceSystemCertificate() |
| 852 | allowed := ctx.Config().EnforceSystemCertificateAllowList() |
| 853 | |
| 854 | if enforceSystemCert && !inList(m.Name(), allowed) { |
| 855 | ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.") |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 860 | return mainCertificate, certificates |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 863 | func (a *AndroidApp) InstallApkName() string { |
| 864 | return a.installApkName |
| 865 | } |
| 866 | |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 867 | func (a *AndroidApp) createPrivappAllowlist(ctx android.ModuleContext) android.Path { |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 868 | if a.appProperties.Privapp_allowlist == nil { |
| 869 | return nil |
| 870 | } |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 871 | |
| 872 | isOverrideApp := a.GetOverriddenBy() != "" |
| 873 | if !isOverrideApp { |
| 874 | // if this is not an override, we don't need to rewrite the existing privapp allowlist |
| 875 | return android.PathForModuleSrc(ctx, *a.appProperties.Privapp_allowlist) |
| 876 | } |
| 877 | |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 878 | packageNameProp := a.overridableAppProperties.Package_name.Get(ctx) |
| 879 | if packageNameProp.IsEmpty() { |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 880 | ctx.PropertyErrorf("privapp_allowlist", "package_name must be set to use privapp_allowlist") |
| 881 | } |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 882 | |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 883 | packageName := packageNameProp.Get() |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 884 | fileName := "privapp_allowlist_" + packageName + ".xml" |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 885 | outPath := android.PathForModuleOut(ctx, fileName) |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 886 | ctx.Build(pctx, android.BuildParams{ |
| 887 | Rule: modifyAllowlist, |
| 888 | Input: android.PathForModuleSrc(ctx, *a.appProperties.Privapp_allowlist), |
| 889 | Output: outPath, |
| 890 | Args: map[string]string{ |
| 891 | "packageName": packageName, |
| 892 | }, |
| 893 | }) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 894 | return outPath |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 897 | func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 898 | var apkDeps android.Paths |
| 899 | |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 900 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 901 | if !apexInfo.IsForPlatform() { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 902 | a.hideApexVariantFromMake = true |
| 903 | } |
| 904 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 905 | a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx) |
| 906 | a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex) |
| 907 | |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 908 | // Unlike installApkName, a.stem should respect base module name for override_android_app. |
| 909 | // Therefore, use ctx.ModuleName() instead of a.Name(). |
yangbill | 2af0b6e | 2024-03-15 09:29:29 +0000 | [diff] [blame] | 910 | a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName()) |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 911 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 912 | // Check if the install APK name needs to be overridden. |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 913 | // Both android_app and override_android_app module are expected to possess |
| 914 | // its module bound apk path. However, override_android_app inherits ctx.ModuleName() |
| 915 | // from the base module. Therefore, use a.Name() which represents |
| 916 | // the module name for both android_app and override_android_app. |
| 917 | a.installApkName = ctx.DeviceConfig().OverridePackageNameFor( |
yangbill | 2af0b6e | 2024-03-15 09:29:29 +0000 | [diff] [blame] | 918 | proptools.StringDefault(a.overridableProperties.Stem, a.Name())) |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 919 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 920 | if ctx.ModuleName() == "framework-res" { |
| 921 | // framework-res.apk is installed as system/framework/framework-res.apk |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 922 | a.installDir = android.PathForModuleInstall(ctx, "framework") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 923 | } else if a.Privileged() { |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 924 | a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName) |
| 925 | } else if ctx.InstallInTestcases() { |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 926 | a.installDir = android.PathForModuleInstall(ctx, a.installApkName, ctx.DeviceConfig().DeviceArch()) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 927 | } else { |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 928 | a.installDir = android.PathForModuleInstall(ctx, "app", a.installApkName) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 929 | } |
Jaewoong Jung | 7dd4ae2 | 2019-09-27 17:13:15 -0700 | [diff] [blame] | 930 | a.onDeviceDir = android.InstallPathToOnDevicePath(ctx, a.installDir) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 931 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 932 | a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 933 | if a.usesLibrary.shouldDisableDexpreopt { |
| 934 | a.dexpreopter.disableDexpreopt() |
| 935 | } |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 936 | |
Colin Cross | 61fb62e | 2022-06-23 10:46:28 -0700 | [diff] [blame] | 937 | var noticeAssetPath android.WritablePath |
| 938 | if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { |
| 939 | // The rule to create the notice file can't be generated yet, as the final output path |
| 940 | // for the apk isn't known yet. Add the path where the notice file will be generated to the |
| 941 | // aapt rules now before calling aaptBuildActions, the rule to create the notice file will |
| 942 | // be generated later. |
| 943 | noticeAssetPath = android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") |
| 944 | a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath) |
| 945 | } |
| 946 | |
Harshit Mahajan | 8f202ad | 2023-01-09 20:45:55 +0000 | [diff] [blame] | 947 | // For apps targeting latest target_sdk_version |
| 948 | if Bool(a.appProperties.Enforce_default_target_sdk_version) { |
| 949 | a.SetEnforceDefaultTargetSdkVersion(true) |
| 950 | } |
| 951 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 952 | // Process all building blocks, from AAPT to certificates. |
| 953 | a.aaptBuildActions(ctx) |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 954 | // The decision to enforce <uses-library> checks is made before adding implicit SDK libraries. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 955 | a.usesLibrary.freezeEnforceUsesLibraries(ctx) |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 956 | |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 957 | // Check that the <uses-library> list is coherent with the manifest. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 958 | if a.usesLibrary.enforceUsesLibraries(ctx) { |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 959 | manifestCheckFile := a.usesLibrary.verifyUsesLibrariesManifest( |
| 960 | ctx, a.mergedManifestFile, &a.classLoaderContexts) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 961 | apkDeps = append(apkDeps, manifestCheckFile) |
| 962 | } |
| 963 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 964 | a.proguardBuildActions(ctx) |
| 965 | |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 966 | a.linter.mergedManifest = a.aapt.mergedManifestFile |
| 967 | a.linter.manifest = a.aapt.manifestPath |
| 968 | a.linter.resources = a.aapt.resourceFiles |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 969 | a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps() |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 970 | |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 971 | dexJarFile, packageResources := a.dexBuildActions(ctx) |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 972 | |
Jiyong Park | 92d8404 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 973 | // No need to check the SDK version of the JNI deps unless we embed them |
| 974 | checkNativeSdkVersion := a.shouldEmbedJnis(ctx) && !Bool(a.appProperties.Jni_uses_platform_apis) |
| 975 | jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), checkNativeSdkVersion) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 976 | jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx) |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 977 | |
| 978 | if ctx.Failed() { |
| 979 | return |
| 980 | } |
| 981 | |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 982 | a.certificate, certificates = processMainCert(a.ModuleBase, a.getCertString(ctx), certificates, ctx) |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 983 | |
| 984 | // Build a final signed app package. |
Jaewoong Jung | 5a49881 | 2019-11-07 14:14:38 -0800 | [diff] [blame] | 985 | packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk") |
Songchun Fan | 17d69e3 | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 986 | v4SigningRequested := Bool(a.Module.deviceProperties.V4_signature) |
| 987 | var v4SignatureFile android.WritablePath = nil |
| 988 | if v4SigningRequested { |
| 989 | v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+".apk.idsig") |
| 990 | } |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 991 | var lineageFile android.Path |
| 992 | if lineage := String(a.overridableAppProperties.Lineage); lineage != "" { |
| 993 | lineageFile = android.PathForModuleSrc(ctx, lineage) |
| 994 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 995 | rotationMinSdkVersion := String(a.overridableAppProperties.RotationMinSdkVersion) |
| 996 | |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 997 | CreateAndSignAppPackage(ctx, packageFile, packageResources, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 998 | a.outputFile = packageFile |
Songchun Fan | 17d69e3 | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 999 | if v4SigningRequested { |
| 1000 | a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) |
| 1001 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1002 | |
Colin Cross | 61fb62e | 2022-06-23 10:46:28 -0700 | [diff] [blame] | 1003 | if a.aapt.noticeFile.Valid() { |
| 1004 | // Generating the notice file rule has to be here after a.outputFile is known. |
Bob Badour | eef4c1c | 2022-05-16 12:20:04 -0700 | [diff] [blame] | 1005 | noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz") |
Bob Badour | c6ec9fb | 2022-06-08 15:59:35 -0700 | [diff] [blame] | 1006 | android.BuildNoticeHtmlOutputFromLicenseMetadata( |
| 1007 | ctx, noticeFile, "", "", |
| 1008 | []string{ |
| 1009 | a.installDir.String() + "/", |
| 1010 | android.PathForModuleInstall(ctx).String() + "/", |
| 1011 | a.outputFile.String(), |
| 1012 | }) |
Bob Badour | eef4c1c | 2022-05-16 12:20:04 -0700 | [diff] [blame] | 1013 | builder := android.NewRuleBuilder(pctx, ctx) |
| 1014 | builder.Command().Text("cp"). |
| 1015 | Input(noticeFile). |
| 1016 | Output(noticeAssetPath) |
| 1017 | builder.Build("notice_dir", "Building notice dir") |
Bob Badour | eef4c1c | 2022-05-16 12:20:04 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 1020 | for _, split := range a.aapt.splits { |
| 1021 | // Sign the split APKs |
Jaewoong Jung | 5a49881 | 2019-11-07 14:14:38 -0800 | [diff] [blame] | 1022 | packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk") |
Songchun Fan | 17d69e3 | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1023 | if v4SigningRequested { |
| 1024 | v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig") |
| 1025 | } |
Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 1026 | CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion) |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 1027 | a.extraOutputFiles = append(a.extraOutputFiles, packageFile) |
Songchun Fan | 17d69e3 | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1028 | if v4SigningRequested { |
| 1029 | a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) |
| 1030 | } |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 1033 | // Build an app bundle. |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 1034 | bundleFile := android.PathForModuleOut(ctx, "base.zip") |
| 1035 | BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile) |
| 1036 | a.bundleFile = bundleFile |
| 1037 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1038 | allowlist := a.createPrivappAllowlist(ctx) |
| 1039 | if allowlist != nil { |
| 1040 | a.privAppAllowlist = android.OptionalPathForPath(allowlist) |
| 1041 | } |
| 1042 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 1043 | // Install the app package. |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1044 | shouldInstallAppPackage := (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() && !a.appProperties.PreventInstall |
| 1045 | if shouldInstallAppPackage { |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 1046 | if a.privAppAllowlist.Valid() { |
Anton Hansson | 0e486a4 | 2023-06-01 16:38:35 +0000 | [diff] [blame] | 1047 | allowlistInstallPath := android.PathForModuleInstall(ctx, "etc", "permissions") |
| 1048 | allowlistInstallFilename := a.installApkName + ".xml" |
| 1049 | ctx.InstallFile(allowlistInstallPath, allowlistInstallFilename, a.privAppAllowlist.Path()) |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 1052 | var extraInstalledPaths android.InstallPaths |
Jiyong Park | 8ba50f9 | 2019-11-13 15:01:01 +0900 | [diff] [blame] | 1053 | for _, extra := range a.extraOutputFiles { |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 1054 | installed := ctx.InstallFile(a.installDir, extra.Base(), extra) |
| 1055 | extraInstalledPaths = append(extraInstalledPaths, installed) |
Jiyong Park | 8ba50f9 | 2019-11-13 15:01:01 +0900 | [diff] [blame] | 1056 | } |
Jiyong Park | 25b9222 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 1057 | // If we don't embed jni libs, make sure that those are installed along with the |
| 1058 | // app, and also place symlinks to the installed paths under the lib/<arch> |
| 1059 | // directory of the app installation directory. ex: |
| 1060 | // /system/app/MyApp/lib/arm64/libfoo.so -> /system/lib64/libfoo.so |
| 1061 | if !a.embeddedJniLibs { |
| 1062 | for _, jniLib := range jniLibs { |
| 1063 | archStr := jniLib.target.Arch.ArchType.String() |
| 1064 | symlinkDir := a.installDir.Join(ctx, "lib", archStr) |
| 1065 | for _, installedLib := range jniLib.installPaths { |
Jiyong Park | 25b9222 | 2024-05-17 22:58:54 +0000 | [diff] [blame] | 1066 | // install the symlink itself |
| 1067 | symlinkName := installedLib.Base() |
| 1068 | symlinkTarget := android.InstallPathToOnDevicePath(ctx, installedLib) |
| 1069 | ctx.InstallAbsoluteSymlink(symlinkDir, symlinkName, symlinkTarget) |
| 1070 | } |
| 1071 | } |
| 1072 | } |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 1073 | ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile, extraInstalledPaths...) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 1074 | } |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1075 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 1076 | ctx.CheckbuildFile(a.outputFile) |
| 1077 | |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1078 | a.buildAppDependencyInfo(ctx) |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 1079 | |
| 1080 | providePrebuiltInfo(ctx, |
| 1081 | prebuiltInfoProps{ |
| 1082 | baseModuleName: a.BaseModuleName(), |
| 1083 | isPrebuilt: false, |
| 1084 | }, |
| 1085 | ) |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 1086 | |
| 1087 | a.setOutputFiles(ctx) |
| 1088 | } |
| 1089 | |
| 1090 | func (a *AndroidApp) setOutputFiles(ctx android.ModuleContext) { |
| 1091 | ctx.SetOutputFiles([]android.Path{a.proguardOptionsFile}, ".aapt.proguardOptionsFile") |
| 1092 | if a.aaptSrcJar != nil { |
| 1093 | ctx.SetOutputFiles([]android.Path{a.aaptSrcJar}, ".aapt.srcjar") |
| 1094 | } |
| 1095 | if a.rJar != nil { |
| 1096 | ctx.SetOutputFiles([]android.Path{a.rJar}, ".aapt.jar") |
| 1097 | } |
| 1098 | ctx.SetOutputFiles([]android.Path{a.outputFile}, ".apk") |
| 1099 | ctx.SetOutputFiles([]android.Path{a.exportPackage}, ".export-package.apk") |
| 1100 | ctx.SetOutputFiles([]android.Path{a.aapt.manifestPath}, ".manifest.xml") |
| 1101 | setOutputFiles(ctx, a.Library.Module) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1104 | type appDepsInterface interface { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1105 | SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1106 | MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1107 | RequiresStableAPIs(ctx android.BaseModuleContext) bool |
| 1108 | } |
| 1109 | |
| 1110 | func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, |
| 1111 | shouldCollectRecursiveNativeDeps bool, |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1112 | checkNativeSdkVersion bool) ([]jniLib, android.Paths, []Certificate) { |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1113 | |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1114 | if checkNativeSdkVersion { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1115 | checkNativeSdkVersion = app.SdkVersion(ctx).Specified() && |
| 1116 | app.SdkVersion(ctx).Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx) |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1117 | } |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1118 | jniLib, prebuiltJniPackages := collectJniDeps(ctx, shouldCollectRecursiveNativeDeps, |
Spandan Das | 10c4136 | 2024-12-03 01:33:09 +0000 | [diff] [blame] | 1119 | checkNativeSdkVersion, func(parent, child android.Module) bool { |
| 1120 | apkInApex := ctx.Module().(android.ApexModule).NotInPlatform() |
| 1121 | childLinkable, _ := child.(cc.LinkableInterface) |
| 1122 | parentLinkable, _ := parent.(cc.LinkableInterface) |
| 1123 | useStubsOfDep := childLinkable.IsStubs() |
| 1124 | if apkInApex && parentLinkable != nil { |
| 1125 | // APK-in-APEX |
| 1126 | // If the parent is a linkable interface, use stubs if the dependency edge crosses an apex boundary. |
| 1127 | useStubsOfDep = useStubsOfDep || (childLinkable.HasStubsVariants() && cc.ShouldUseStubForApex(ctx, parent, child)) |
| 1128 | } |
| 1129 | return !childLinkable.IsNdk(ctx.Config()) && !useStubsOfDep |
| 1130 | }) |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1131 | |
| 1132 | var certificates []Certificate |
| 1133 | |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1134 | var directImplementationDeps android.Paths |
| 1135 | var transitiveImplementationDeps []depset.DepSet[android.Path] |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1136 | ctx.VisitDirectDeps(func(module android.Module) { |
| 1137 | otherName := ctx.OtherModuleName(module) |
| 1138 | tag := ctx.OtherModuleDependencyTag(module) |
| 1139 | |
| 1140 | if tag == certificateTag { |
| 1141 | if dep, ok := module.(*AndroidAppCertificate); ok { |
| 1142 | certificates = append(certificates, dep.Certificate) |
| 1143 | } else { |
| 1144 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) |
| 1145 | } |
| 1146 | } |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1147 | |
| 1148 | if IsJniDepTag(tag) { |
| 1149 | directImplementationDeps = append(directImplementationDeps, android.OutputFileForModule(ctx, module, "")) |
| 1150 | if info, ok := android.OtherModuleProvider(ctx, module, cc.ImplementationDepInfoProvider); ok { |
| 1151 | transitiveImplementationDeps = append(transitiveImplementationDeps, info.ImplementationDeps) |
| 1152 | } |
| 1153 | } |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1154 | }) |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1155 | android.SetProvider(ctx, cc.ImplementationDepInfoProvider, &cc.ImplementationDepInfo{ |
| 1156 | ImplementationDeps: depset.New(depset.PREORDER, directImplementationDeps, transitiveImplementationDeps), |
| 1157 | }) |
| 1158 | |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1159 | return jniLib, prebuiltJniPackages, certificates |
| 1160 | } |
| 1161 | |
| 1162 | func collectJniDeps(ctx android.ModuleContext, |
| 1163 | shouldCollectRecursiveNativeDeps bool, |
| 1164 | checkNativeSdkVersion bool, |
Spandan Das | 10c4136 | 2024-12-03 01:33:09 +0000 | [diff] [blame] | 1165 | filter func(parent, child android.Module) bool) ([]jniLib, android.Paths) { |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1166 | var jniLibs []jniLib |
| 1167 | var prebuiltJniPackages android.Paths |
| 1168 | seenModulePaths := make(map[string]bool) |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1169 | |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1170 | ctx.WalkDeps(func(module android.Module, parent android.Module) bool { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1171 | otherName := ctx.OtherModuleName(module) |
| 1172 | tag := ctx.OtherModuleDependencyTag(module) |
| 1173 | |
Colin Cross | f0913fb | 2020-07-29 12:59:39 -0700 | [diff] [blame] | 1174 | if IsJniDepTag(tag) || cc.IsSharedDepTag(tag) { |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 1175 | if dep, ok := module.(cc.LinkableInterface); ok { |
Spandan Das | 10c4136 | 2024-12-03 01:33:09 +0000 | [diff] [blame] | 1176 | if filter != nil && !filter(parent, module) { |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1177 | return false |
| 1178 | } |
| 1179 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1180 | lib := dep.OutputFile() |
| 1181 | if lib.Valid() { |
Cole Faust | 64cb7c9 | 2021-09-14 17:32:49 -0700 | [diff] [blame] | 1182 | path := lib.Path() |
| 1183 | if seenModulePaths[path.String()] { |
| 1184 | return false |
| 1185 | } |
| 1186 | seenModulePaths[path.String()] = true |
| 1187 | |
| 1188 | if checkNativeSdkVersion && dep.SdkVersion() == "" { |
| 1189 | ctx.PropertyErrorf("jni_libs", "JNI dependency %q uses platform APIs, but this module does not", |
| 1190 | otherName) |
| 1191 | } |
| 1192 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1193 | jniLibs = append(jniLibs, jniLib{ |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 1194 | name: ctx.OtherModuleName(module), |
| 1195 | path: path, |
| 1196 | target: module.Target(), |
| 1197 | coverageFile: dep.CoverageOutputFile(), |
| 1198 | unstrippedFile: dep.UnstrippedOutputFile(), |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 1199 | partition: dep.Partition(), |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 1200 | installPaths: android.OtherModuleProviderOrDefault(ctx, dep, android.InstallFilesProvider).InstallFiles, |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1201 | }) |
Colin Cross | dd5261c | 2022-12-19 12:26:43 -0800 | [diff] [blame] | 1202 | } else if ctx.Config().AllowMissingDependencies() { |
| 1203 | ctx.AddMissingDependencies([]string{otherName}) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1204 | } else { |
| 1205 | ctx.ModuleErrorf("dependency %q missing output file", otherName) |
| 1206 | } |
| 1207 | } else { |
| 1208 | ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1209 | } |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1210 | |
| 1211 | return shouldCollectRecursiveNativeDeps |
| 1212 | } |
| 1213 | |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1214 | if info, ok := android.OtherModuleProvider(ctx, module, JniPackageProvider); ok { |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1215 | prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) |
| 1216 | } |
| 1217 | |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1218 | return false |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1219 | }) |
| 1220 | |
Makoto Onuki | 2ca8427 | 2024-02-10 00:15:21 +0000 | [diff] [blame] | 1221 | return jniLibs, prebuiltJniPackages |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Colin Cross | 8bf14fc | 2024-09-25 16:41:31 -0700 | [diff] [blame] | 1224 | func (a *AndroidApp) WalkPayloadDeps(ctx android.BaseModuleContext, do android.PayloadDepsCallback) { |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1225 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 1226 | // TODO(ccross): Should this use android.DepIsInSameApex? Right now it is applying the android app |
| 1227 | // heuristics to every transitive dependency, when it should probably be using the heuristics of the |
| 1228 | // immediate parent. |
| 1229 | isExternal := !a.OutgoingDepIsInSameApex(ctx.OtherModuleDependencyTag(child)) |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1230 | if am, ok := child.(android.ApexModule); ok { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1231 | if !do(ctx, parent, am, isExternal) { |
| 1232 | return false |
| 1233 | } |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1234 | } |
| 1235 | return !isExternal |
| 1236 | }) |
| 1237 | } |
| 1238 | |
| 1239 | func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { |
| 1240 | if ctx.Host() { |
| 1241 | return |
| 1242 | } |
| 1243 | |
| 1244 | depsInfo := android.DepNameToDepInfoMap{} |
Colin Cross | 9cf55a5 | 2024-12-05 14:26:03 -0800 | [diff] [blame] | 1245 | a.WalkPayloadDeps(ctx, func(ctx android.BaseModuleContext, from android.Module, to android.ApexModule, externalDep bool) bool { |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1246 | depName := to.Name() |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 1247 | |
| 1248 | // Skip dependencies that are only available to APEXes; they are developed with updatability |
| 1249 | // in mind and don't need manual approval. |
| 1250 | if to.(android.ApexModule).NotAvailableForPlatform() { |
| 1251 | return true |
| 1252 | } |
| 1253 | |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1254 | if info, exist := depsInfo[depName]; exist { |
| 1255 | info.From = append(info.From, from.Name()) |
| 1256 | info.IsExternal = info.IsExternal && externalDep |
| 1257 | depsInfo[depName] = info |
| 1258 | } else { |
| 1259 | toMinSdkVersion := "(no version)" |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1260 | if m, ok := to.(interface { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1261 | MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1262 | }); ok { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1263 | if v := m.MinSdkVersion(ctx); !v.IsNone() { |
| 1264 | toMinSdkVersion = v.String() |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1265 | } |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1266 | } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { |
| 1267 | // TODO(b/175678607) eliminate the use of MinSdkVersion returning |
| 1268 | // string |
| 1269 | if v := m.MinSdkVersion(); v != "" { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1270 | toMinSdkVersion = v |
| 1271 | } |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1272 | } |
| 1273 | depsInfo[depName] = android.ApexModuleDepInfo{ |
| 1274 | To: depName, |
| 1275 | From: []string{from.Name()}, |
| 1276 | IsExternal: externalDep, |
| 1277 | MinSdkVersion: toMinSdkVersion, |
| 1278 | } |
| 1279 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1280 | return true |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1281 | }) |
| 1282 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1283 | a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depsInfo) |
Artur Satayev | 1111b84 | 2020-04-27 19:05:28 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 1286 | func (a *AndroidApp) enforceDefaultTargetSdkVersion() bool { |
| 1287 | return a.appProperties.EnforceDefaultTargetSdkVersion |
| 1288 | } |
| 1289 | |
| 1290 | func (a *AndroidApp) SetEnforceDefaultTargetSdkVersion(val bool) { |
| 1291 | a.appProperties.EnforceDefaultTargetSdkVersion = val |
| 1292 | } |
| 1293 | |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 1294 | func (a *AndroidApp) Updatable() bool { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1295 | return Bool(a.appProperties.Updatable) |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 1296 | } |
| 1297 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1298 | func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string { |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1299 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 1300 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1301 | return ":" + certificate |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1302 | } |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 1303 | return a.overridableAppProperties.Certificate.GetOrDefault(ctx, "") |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 1306 | func (a *AndroidApp) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { |
| 1307 | if IsJniDepTag(tag) { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1308 | return true |
| 1309 | } |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 1310 | return a.Library.OutgoingDepIsInSameApex(tag) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1311 | } |
| 1312 | |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1313 | func (a *AndroidApp) Privileged() bool { |
| 1314 | return Bool(a.appProperties.Privileged) |
| 1315 | } |
| 1316 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 1317 | func (a *AndroidApp) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1318 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1321 | func (a *AndroidApp) SetPreventInstall() { |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 1322 | a.appProperties.PreventInstall = true |
| 1323 | } |
| 1324 | |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 1325 | func (a *AndroidApp) MarkAsCoverageVariant(coverage bool) { |
| 1326 | a.appProperties.IsCoverageVariant = coverage |
| 1327 | } |
| 1328 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1329 | func (a *AndroidApp) EnableCoverageIfNeeded() {} |
| 1330 | |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 1331 | var _ cc.Coverage = (*AndroidApp)(nil) |
| 1332 | |
Cole Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 1333 | func (a *AndroidApp) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) { |
| 1334 | a.Library.IDEInfo(ctx, dpInfo) |
| 1335 | a.aapt.IDEInfo(ctx, dpInfo) |
Colin Cross | 95b53b8 | 2023-10-17 13:21:02 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1338 | func (a *AndroidApp) productCharacteristicsRROPackageName() string { |
| 1339 | return proptools.String(a.appProperties.ProductCharacteristicsRROPackageName) |
| 1340 | } |
| 1341 | |
| 1342 | func (a *AndroidApp) productCharacteristicsRROManifestModuleName() string { |
| 1343 | return proptools.String(a.appProperties.ProductCharacteristicsRROManifestModuleName) |
| 1344 | } |
| 1345 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1346 | // android_app compiles sources and Android resources into an Android application package `.apk` file. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1347 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1348 | module := &AndroidApp{} |
| 1349 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1350 | module.Module.dexProperties.Optimize.EnabledByDefault = true |
| 1351 | module.Module.dexProperties.Optimize.Shrink = proptools.BoolPtr(true) |
Jared Duke | aa88b3d | 2023-08-29 17:07:20 +0000 | [diff] [blame] | 1352 | module.Module.dexProperties.Optimize.Proguard_compatibility = proptools.BoolPtr(false) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 1353 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1354 | module.Module.properties.Instrument = true |
Paul Duffin | 0038a8d | 2022-05-03 00:28:40 +0000 | [diff] [blame] | 1355 | module.Module.properties.Supports_static_instrumentation = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1356 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1357 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1358 | module.addHostAndDeviceProperties() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1359 | module.AddProperties( |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1360 | &module.aaptProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1361 | &module.appProperties, |
Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 1362 | &module.overridableAppProperties, |
| 1363 | &module.Library.sourceProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1364 | |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 1365 | module.usesLibrary.enforce = true |
| 1366 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1367 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1368 | android.InitDefaultableModule(module) |
zhidou | 198f589 | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 1369 | android.InitOverridableModule(module, &module.overridableAppProperties.Overrides) |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1370 | android.InitApexModule(module) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1371 | |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1372 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 1373 | a := ctx.Module().(*AndroidApp) |
| 1374 | |
| 1375 | characteristics := ctx.Config().ProductAAPTCharacteristics() |
| 1376 | if characteristics == "default" || characteristics == "" { |
| 1377 | module.appProperties.Generate_product_characteristics_rro = nil |
| 1378 | // no need to create RRO |
| 1379 | return |
| 1380 | } |
| 1381 | |
| 1382 | if !proptools.Bool(module.appProperties.Generate_product_characteristics_rro) { |
| 1383 | return |
| 1384 | } |
| 1385 | |
| 1386 | rroPackageName := a.Name() + "__" + strings.ReplaceAll(characteristics, ",", "_") + "__auto_generated_characteristics_rro" |
| 1387 | rroManifestName := rroPackageName + "_manifest" |
| 1388 | |
| 1389 | a.appProperties.ProductCharacteristicsRROPackageName = proptools.StringPtr(rroPackageName) |
| 1390 | a.appProperties.ProductCharacteristicsRROManifestModuleName = proptools.StringPtr(rroManifestName) |
| 1391 | |
| 1392 | rroManifestProperties := struct { |
| 1393 | Name *string |
| 1394 | Tools []string |
| 1395 | Out []string |
| 1396 | Srcs []string |
| 1397 | Cmd *string |
| 1398 | }{ |
| 1399 | Name: proptools.StringPtr(rroManifestName), |
Inseob Kim | 5b90d3a | 2024-02-14 16:55:33 +0900 | [diff] [blame] | 1400 | Tools: []string{"characteristics_rro_generator", "aapt2"}, |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1401 | Out: []string{"AndroidManifest.xml"}, |
Inseob Kim | 5b90d3a | 2024-02-14 16:55:33 +0900 | [diff] [blame] | 1402 | Srcs: []string{":" + a.Name() + "{.apk}"}, |
| 1403 | Cmd: proptools.StringPtr("$(location characteristics_rro_generator) $$($(location aapt2) dump packagename $(in)) $(out)"), |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1404 | } |
Cole Faust | e19d335 | 2024-10-17 10:30:57 -0700 | [diff] [blame] | 1405 | ctx.CreateModule(GenRuleFactory, &rroManifestProperties) |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1406 | |
| 1407 | rroProperties := struct { |
| 1408 | Name *string |
| 1409 | Filter_product *string |
| 1410 | Aaptflags []string |
| 1411 | Manifest *string |
Cole Faust | 5b98977 | 2024-11-06 11:03:16 -0800 | [diff] [blame] | 1412 | Resource_dirs proptools.Configurable[[]string] |
Jihoon Kang | f62f422 | 2024-10-21 23:06:41 +0000 | [diff] [blame] | 1413 | Flags_packages []string |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1414 | }{ |
| 1415 | Name: proptools.StringPtr(rroPackageName), |
| 1416 | Filter_product: proptools.StringPtr(characteristics), |
| 1417 | Aaptflags: []string{"--auto-add-overlay"}, |
| 1418 | Manifest: proptools.StringPtr(":" + rroManifestName), |
| 1419 | Resource_dirs: a.aaptProperties.Resource_dirs, |
Jihoon Kang | f62f422 | 2024-10-21 23:06:41 +0000 | [diff] [blame] | 1420 | Flags_packages: a.aaptProperties.Flags_packages, |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1421 | } |
优秀 | d75e998 | 2024-05-09 07:15:55 +0000 | [diff] [blame] | 1422 | if !Bool(a.aaptProperties.Aapt_include_all_resources) { |
| 1423 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
| 1424 | rroProperties.Aaptflags = append(rroProperties.Aaptflags, "-c", aaptConfig) |
| 1425 | } |
| 1426 | } |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1427 | ctx.CreateModule(RuntimeResourceOverlayFactory, &rroProperties) |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 1428 | |
| 1429 | }) |
| 1430 | |
| 1431 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
| 1432 | createInternalRuntimeOverlays(ctx, module.ModuleBase) |
Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 1433 | }) |
| 1434 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1435 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1436 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1437 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1438 | func AutogeneratedRroModuleName(ctx android.EarlyModuleContext, moduleName, partition string) string { |
| 1439 | return fmt.Sprintf("%s__%s__auto_generated_rro_%s", moduleName, ctx.Config().DeviceProduct(), partition) |
| 1440 | } |
| 1441 | |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 1442 | type createModuleContext interface { |
| 1443 | android.EarlyModuleContext |
| 1444 | CreateModule(android.ModuleFactory, ...interface{}) android.Module |
| 1445 | } |
| 1446 | |
| 1447 | func createInternalRuntimeOverlays(ctx createModuleContext, a android.ModuleBase) { |
| 1448 | if !ctx.Config().HasDeviceProduct() { |
| 1449 | return |
| 1450 | } |
| 1451 | // vendor |
| 1452 | vendorOverlayProps := struct { |
| 1453 | Name *string |
| 1454 | Base *string |
| 1455 | Vendor *bool |
| 1456 | Product_specific *bool |
| 1457 | System_ext_specific *bool |
| 1458 | Manifest *string |
| 1459 | Sdk_version *string |
| 1460 | Compile_multilib *string |
| 1461 | Enabled proptools.Configurable[bool] |
| 1462 | }{ |
| 1463 | Name: proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "vendor")), |
| 1464 | Base: proptools.StringPtr(a.Name()), |
| 1465 | Vendor: proptools.BoolPtr(true), |
| 1466 | Product_specific: proptools.BoolPtr(false), |
| 1467 | System_ext_specific: proptools.BoolPtr(false), |
| 1468 | Manifest: proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"), |
| 1469 | Sdk_version: proptools.StringPtr("current"), |
| 1470 | Compile_multilib: proptools.StringPtr("first"), |
| 1471 | Enabled: a.EnabledProperty().Clone(), |
| 1472 | } |
| 1473 | ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &vendorOverlayProps) |
| 1474 | |
| 1475 | // product |
| 1476 | productOverlayProps := struct { |
| 1477 | Name *string |
| 1478 | Base *string |
| 1479 | Vendor *bool |
| 1480 | Proprietary *bool |
| 1481 | Soc_specific *bool |
| 1482 | Product_specific *bool |
| 1483 | System_ext_specific *bool |
| 1484 | Manifest *string |
| 1485 | Sdk_version *string |
| 1486 | Compile_multilib *string |
| 1487 | Enabled proptools.Configurable[bool] |
| 1488 | }{ |
| 1489 | Name: proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "product")), |
| 1490 | Base: proptools.StringPtr(a.Name()), |
| 1491 | Vendor: proptools.BoolPtr(false), |
| 1492 | Proprietary: proptools.BoolPtr(false), |
| 1493 | Soc_specific: proptools.BoolPtr(false), |
| 1494 | Product_specific: proptools.BoolPtr(true), |
| 1495 | System_ext_specific: proptools.BoolPtr(false), |
| 1496 | Manifest: proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"), |
| 1497 | Sdk_version: proptools.StringPtr("current"), |
| 1498 | Compile_multilib: proptools.StringPtr("first"), |
| 1499 | Enabled: a.EnabledProperty().Clone(), |
| 1500 | } |
| 1501 | ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &productOverlayProps) |
| 1502 | } |
| 1503 | |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 1504 | // A dictionary of values to be overridden in the manifest. |
| 1505 | type Manifest_values struct { |
| 1506 | // Overrides the value of package_name in the manifest |
| 1507 | ApplicationId *string |
| 1508 | } |
| 1509 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1510 | type appTestProperties struct { |
Liz Kammer | 6b0c552 | 2020-04-28 16:10:55 -0700 | [diff] [blame] | 1511 | // The name of the android_app module that the tests will run against. |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1512 | Instrumentation_for *string |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1513 | |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 1514 | // If specified, the instrumentation target package name in the manifest is overwritten by it. |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1515 | Instrumentation_target_package *string |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 1516 | |
| 1517 | // If specified, the mainline module package name in the test config is overwritten by it. |
| 1518 | Mainline_package_name *string |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 1519 | |
| 1520 | Manifest_values Manifest_values |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | type AndroidTest struct { |
| 1524 | AndroidApp |
| 1525 | |
| 1526 | appTestProperties appTestProperties |
| 1527 | |
| 1528 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1529 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 1530 | testConfig android.Path |
| 1531 | extraTestConfigs android.Paths |
| 1532 | data android.Paths |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Jaewoong Jung | 0949f31 | 2019-09-11 10:25:18 -0700 | [diff] [blame] | 1535 | func (a *AndroidTest) InstallInTestcases() bool { |
| 1536 | return true |
| 1537 | } |
| 1538 | |
Spandan Das | 9f7ae7f | 2022-07-25 00:34:18 +0000 | [diff] [blame] | 1539 | type androidTestApp interface { |
| 1540 | includedInTestSuite(searchPrefix string) bool |
| 1541 | } |
| 1542 | |
| 1543 | func (a *AndroidTest) includedInTestSuite(searchPrefix string) bool { |
| 1544 | return android.PrefixInList(a.testProperties.Test_suites, searchPrefix) |
| 1545 | } |
| 1546 | |
| 1547 | func (a *AndroidTestHelperApp) includedInTestSuite(searchPrefix string) bool { |
| 1548 | return android.PrefixInList(a.appTestHelperAppProperties.Test_suites, searchPrefix) |
| 1549 | } |
| 1550 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1551 | func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | b041087 | 2024-06-25 03:30:03 +0000 | [diff] [blame] | 1552 | checkMinSdkVersionMts(ctx, a.MinSdkVersion(ctx)) |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 1553 | var configs []tradefed.Config |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1554 | if a.appTestProperties.Instrumentation_target_package != nil { |
| 1555 | a.additionalAaptFlags = append(a.additionalAaptFlags, |
| 1556 | "--rename-instrumentation-target-package "+*a.appTestProperties.Instrumentation_target_package) |
| 1557 | } else if a.appTestProperties.Instrumentation_for != nil { |
| 1558 | // Check if the instrumentation target package is overridden. |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1559 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for) |
| 1560 | if overridden { |
| 1561 | a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName) |
| 1562 | } |
| 1563 | } |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 1564 | applicationId := a.appTestProperties.Manifest_values.ApplicationId |
| 1565 | if applicationId != nil { |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 1566 | packageNameProp := a.overridableAppProperties.Package_name.Get(ctx) |
| 1567 | if packageNameProp.IsPresent() { |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 1568 | ctx.PropertyErrorf("manifest_values.applicationId", "property is not supported when property package_name is set.") |
| 1569 | } |
| 1570 | a.aapt.manifestValues.applicationId = *applicationId |
| 1571 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1572 | a.generateAndroidBuildActions(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1573 | |
Jiyong Park | f528b70 | 2024-12-30 16:01:58 +0900 | [diff] [blame] | 1574 | for _, c := range a.testProperties.Test_options.Tradefed_options { |
| 1575 | configs = append(configs, c) |
| 1576 | } |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 1577 | for _, module := range a.testProperties.Test_mainline_modules { |
| 1578 | configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module}) |
| 1579 | } |
| 1580 | |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1581 | testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, |
Dan Shi | 4b34a72 | 2024-09-26 17:47:16 +0000 | [diff] [blame] | 1582 | a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, |
| 1583 | a.testProperties.Auto_gen_config, configs, a.testProperties.Test_options.Test_runner_options) |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1584 | a.testConfig = a.FixTestConfig(ctx, testConfig) |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 1585 | a.extraTestConfigs = android.PathsForModuleSrc(ctx, a.testProperties.Test_options.Extra_test_configs) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1586 | a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) |
Cole Faust | 65cb40a | 2024-10-21 15:41:42 -0700 | [diff] [blame] | 1587 | a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_common_data)...) |
| 1588 | a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_data)...) |
Cole Faust | 18f03f1 | 2024-10-23 14:51:11 -0700 | [diff] [blame] | 1589 | a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_prefer32_data)...) |
Ronald Braunstein | f424c9a | 2024-10-22 01:41:20 +0000 | [diff] [blame] | 1590 | |
Ronald Braunstein | fce4316 | 2024-02-02 12:37:20 -0800 | [diff] [blame] | 1591 | android.SetProvider(ctx, tradefed.BaseTestProviderKey, tradefed.BaseTestProviderData{ |
Ronald Braunstein | f424c9a | 2024-10-22 01:41:20 +0000 | [diff] [blame] | 1592 | TestcaseRelDataFiles: testcaseRel(a.data), |
Ronald Braunstein | fce4316 | 2024-02-02 12:37:20 -0800 | [diff] [blame] | 1593 | OutputFile: a.OutputFile(), |
| 1594 | TestConfig: a.testConfig, |
| 1595 | HostRequiredModuleNames: a.HostRequiredModuleNames(), |
Ronald Braunstein | 1a6e7c0 | 2024-03-14 21:14:39 +0000 | [diff] [blame] | 1596 | TestSuites: a.testProperties.Test_suites, |
| 1597 | IsHost: false, |
Ronald Braunstein | 01d31bd | 2024-06-02 07:07:02 -0700 | [diff] [blame] | 1598 | LocalCertificate: a.certificate.AndroidMkString(), |
| 1599 | IsUnitTest: Bool(a.testProperties.Test_options.Unit_test), |
Ronald Braunstein | f424c9a | 2024-10-22 01:41:20 +0000 | [diff] [blame] | 1600 | MkInclude: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", |
| 1601 | MkAppClass: "APPS", |
Ronald Braunstein | fce4316 | 2024-02-02 12:37:20 -0800 | [diff] [blame] | 1602 | }) |
Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 1603 | android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ |
| 1604 | TestOnly: true, |
| 1605 | TopLevelTarget: true, |
| 1606 | }) |
| 1607 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Ronald Braunstein | f424c9a | 2024-10-22 01:41:20 +0000 | [diff] [blame] | 1610 | func testcaseRel(paths android.Paths) []string { |
| 1611 | relPaths := []string{} |
| 1612 | for _, p := range paths { |
| 1613 | relPaths = append(relPaths, p.Rel()) |
| 1614 | } |
| 1615 | return relPaths |
| 1616 | } |
| 1617 | |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1618 | func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path { |
| 1619 | if testConfig == nil { |
| 1620 | return nil |
| 1621 | } |
| 1622 | |
| 1623 | fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1624 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1625 | command := rule.Command().BuiltTool("test_config_fixer").Input(testConfig).Output(fixedConfig) |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1626 | fixNeeded := false |
| 1627 | |
Jooyung Han | 29e2f6d | 2022-01-08 12:13:59 +0900 | [diff] [blame] | 1628 | // Auto-generated test config uses `ModuleName` as the APK name. So fix it if it is not the case. |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1629 | if ctx.ModuleName() != a.installApkName { |
| 1630 | fixNeeded = true |
| 1631 | command.FlagWithArg("--test-file-name ", a.installApkName+".apk") |
| 1632 | } |
| 1633 | |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 1634 | packageNameProp := a.overridableAppProperties.Package_name.Get(ctx) |
| 1635 | if packageNameProp.IsPresent() { |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1636 | fixNeeded = true |
| 1637 | command.FlagWithInput("--manifest ", a.manifestPath). |
Cole Faust | 258b96f | 2024-10-04 10:48:24 -0700 | [diff] [blame] | 1638 | FlagWithArg("--package-name ", packageNameProp.Get()) |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 1641 | if a.appTestProperties.Mainline_package_name != nil { |
| 1642 | fixNeeded = true |
| 1643 | command.FlagWithArg("--mainline-package-name ", *a.appTestProperties.Mainline_package_name) |
| 1644 | } |
| 1645 | |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1646 | if fixNeeded { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1647 | rule.Build("fix_test_config", "fix test config") |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 1648 | return fixedConfig |
| 1649 | } |
| 1650 | return testConfig |
| 1651 | } |
| 1652 | |
Yihan Dong | 8be09c2 | 2024-08-29 15:32:13 +0800 | [diff] [blame] | 1653 | func (a *AndroidTestHelperApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1654 | if len(a.ApexProperties.Apex_available) == 0 && ctx.Config().IsEnvTrue("EMMA_API_MAPPER") { |
| 1655 | // Instrument the android_test_helper target to log potential API calls at the run time. |
| 1656 | // Contact android-xts-infra team before using the environment var EMMA_API_MAPPER. |
| 1657 | ctx.AddVariationDependencies(nil, staticLibTag, "apimapper-helper-device-lib") |
| 1658 | a.setApiMapper(true) |
| 1659 | } |
| 1660 | a.AndroidApp.DepsMutator(ctx) |
| 1661 | } |
| 1662 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1663 | func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
Yihan Dong | 8be09c2 | 2024-08-29 15:32:13 +0800 | [diff] [blame] | 1664 | if len(a.ApexProperties.Apex_available) == 0 && ctx.Config().IsEnvTrue("EMMA_API_MAPPER") { |
| 1665 | // Instrument the android_test_helper target to log potential API calls at the run time. |
| 1666 | // Contact android-xts-infra team before using the environment var EMMA_API_MAPPER. |
| 1667 | ctx.AddVariationDependencies(nil, staticLibTag, "apimapper-helper-device-lib") |
| 1668 | a.setApiMapper(true) |
| 1669 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1670 | a.AndroidApp.DepsMutator(ctx) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | func (a *AndroidTest) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 1674 | a.AndroidApp.OverridablePropertiesDepsMutator(ctx) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 1675 | if a.appTestProperties.Instrumentation_for != nil { |
| 1676 | // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac, |
| 1677 | // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so |
| 1678 | // use instrumentationForTag instead of libTag. |
| 1679 | ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for)) |
| 1680 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1683 | // android_test compiles test sources and Android resources into an Android application package `.apk` file and |
| 1684 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1685 | func AndroidTestFactory() android.Module { |
| 1686 | module := &AndroidTest{} |
| 1687 | |
Jared Duke | 63a3da9 | 2022-06-02 19:11:14 +0000 | [diff] [blame] | 1688 | module.Module.dexProperties.Optimize.EnabledByDefault = false |
Colin Cross | 5067db9 | 2018-09-17 16:46:35 -0700 | [diff] [blame] | 1689 | |
| 1690 | module.Module.properties.Instrument = true |
Paul Duffin | 0038a8d | 2022-05-03 00:28:40 +0000 | [diff] [blame] | 1691 | module.Module.properties.Supports_static_instrumentation = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1692 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 1693 | module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) |
| 1694 | module.appProperties.AlwaysPackageNativeLibs = true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1695 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1696 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1697 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1698 | module.addHostAndDeviceProperties() |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1699 | module.AddProperties( |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1700 | &module.aaptProperties, |
| 1701 | &module.appProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 1702 | &module.appTestProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1703 | &module.overridableAppProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 1704 | &module.testProperties) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1705 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1706 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1707 | android.InitDefaultableModule(module) |
zhidou | 198f589 | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 1708 | android.InitOverridableModule(module, &module.overridableAppProperties.Overrides) |
Jingwen Chen | e12c083 | 2023-08-25 09:00:16 +0000 | [diff] [blame] | 1709 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 1710 | return module |
| 1711 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1712 | |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1713 | type appTestHelperAppProperties struct { |
| 1714 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1715 | // installed into. |
| 1716 | Test_suites []string `android:"arch_variant"` |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 1717 | |
| 1718 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 1719 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 1720 | // explicitly. |
| 1721 | Auto_gen_config *bool |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame] | 1722 | |
| 1723 | // Install the test into a folder named for the module in all test suites. |
| 1724 | Per_testcase_directory *bool |
Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 1725 | |
| 1726 | Manifest_values Manifest_values |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | type AndroidTestHelperApp struct { |
| 1730 | AndroidApp |
| 1731 | |
| 1732 | appTestHelperAppProperties appTestHelperAppProperties |
| 1733 | } |
| 1734 | |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 1735 | func (a *AndroidTestHelperApp) InstallInTestcases() bool { |
| 1736 | return true |
| 1737 | } |
| 1738 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1739 | // android_test_helper_app compiles sources and Android resources into an Android application package `.apk` file that |
| 1740 | // will be used by tests, but does not produce an `AndroidTest.xml` file so the module will not be run directly as a |
| 1741 | // test. |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1742 | func AndroidTestHelperAppFactory() android.Module { |
| 1743 | module := &AndroidTestHelperApp{} |
| 1744 | |
Jared Duke | 63a3da9 | 2022-06-02 19:11:14 +0000 | [diff] [blame] | 1745 | // TODO(b/192032291): Disable by default after auditing downstream usage. |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1746 | module.Module.dexProperties.Optimize.EnabledByDefault = true |
Christoffer Adamsen | c8fd1f1 | 2025-01-06 19:04:03 +0100 | [diff] [blame] | 1747 | module.Module.dexProperties.Optimize.Ignore_library_extends_program = proptools.BoolPtr(true) |
| 1748 | module.Module.dexProperties.Optimize.Proguard_compatibility = proptools.BoolPtr(false) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1749 | |
| 1750 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Jiyong Park | d044bb4 | 2024-05-15 02:09:54 +0900 | [diff] [blame] | 1751 | module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) |
| 1752 | module.appProperties.AlwaysPackageNativeLibs = true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1753 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1754 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1755 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1756 | module.addHostAndDeviceProperties() |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1757 | module.AddProperties( |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1758 | &module.aaptProperties, |
| 1759 | &module.appProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1760 | &module.appTestHelperAppProperties, |
Ulya Trafimovich | 21a7375 | 2020-09-01 17:33:48 +0100 | [diff] [blame] | 1761 | &module.overridableAppProperties) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1762 | |
| 1763 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1764 | android.InitDefaultableModule(module) |
Anton Hansson | 3d2b6b4 | 2020-01-10 15:06:01 +0000 | [diff] [blame] | 1765 | android.InitApexModule(module) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 1766 | return module |
| 1767 | } |
| 1768 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1769 | type AndroidAppCertificate struct { |
| 1770 | android.ModuleBase |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 1771 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1772 | properties AndroidAppCertificateProperties |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1773 | Certificate Certificate |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | type AndroidAppCertificateProperties struct { |
| 1777 | // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name. |
| 1778 | Certificate *string |
| 1779 | } |
| 1780 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1781 | // android_app_certificate modules can be referenced by the certificates property of android_app modules to select |
| 1782 | // the signing key. |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1783 | func AndroidAppCertificateFactory() android.Module { |
| 1784 | module := &AndroidAppCertificate{} |
| 1785 | module.AddProperties(&module.properties) |
| 1786 | android.InitAndroidModule(module) |
| 1787 | return module |
| 1788 | } |
| 1789 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1790 | func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1791 | cert := String(c.properties.Certificate) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1792 | c.Certificate = Certificate{ |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 1793 | Pem: android.PathForModuleSrc(ctx, cert+".x509.pem"), |
| 1794 | Key: android.PathForModuleSrc(ctx, cert+".pk8"), |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 1795 | } |
| 1796 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1797 | |
| 1798 | type OverrideAndroidApp struct { |
| 1799 | android.ModuleBase |
| 1800 | android.OverrideModuleBase |
| 1801 | } |
| 1802 | |
Sasha Smundak | 613cbb1 | 2020-06-05 10:27:23 -0700 | [diff] [blame] | 1803 | func (i *OverrideAndroidApp) GenerateAndroidBuildActions(_ android.ModuleContext) { |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1804 | // All the overrides happen in the base module. |
| 1805 | // TODO(jungjw): Check the base module type. |
| 1806 | } |
| 1807 | |
| 1808 | // override_android_app is used to create an android_app module based on another android_app by overriding |
| 1809 | // some of its properties. |
| 1810 | func OverrideAndroidAppModuleFactory() android.Module { |
| 1811 | m := &OverrideAndroidApp{} |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 1812 | m.AddProperties( |
yangbill | 2af0b6e | 2024-03-15 09:29:29 +0000 | [diff] [blame] | 1813 | &OverridableProperties{}, |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 1814 | &overridableAppProperties{}, |
| 1815 | ) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1816 | |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 1817 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1818 | android.InitOverrideModule(m) |
Spandan Das | ef8b3b2 | 2024-12-04 01:34:34 +0000 | [diff] [blame] | 1819 | android.AddLoadHookWithPriority(m, func(ctx android.LoadHookContext) { |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 1820 | createInternalRuntimeOverlays(ctx, m.ModuleBase) |
Spandan Das | ef8b3b2 | 2024-12-04 01:34:34 +0000 | [diff] [blame] | 1821 | }, 1) // Run after soong config load hoook |
Spandan Das | de588a3 | 2024-12-03 22:52:24 +0000 | [diff] [blame] | 1822 | |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1823 | return m |
| 1824 | } |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1825 | |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1826 | type OverrideAndroidTest struct { |
| 1827 | android.ModuleBase |
| 1828 | android.OverrideModuleBase |
| 1829 | } |
| 1830 | |
Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 1831 | func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1832 | // All the overrides happen in the base module. |
| 1833 | // TODO(jungjw): Check the base module type. |
Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 1834 | android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ |
| 1835 | TestOnly: true, |
| 1836 | TopLevelTarget: true, |
| 1837 | }) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | // override_android_test is used to create an android_app module based on another android_test by overriding |
| 1841 | // some of its properties. |
| 1842 | func OverrideAndroidTestModuleFactory() android.Module { |
| 1843 | m := &OverrideAndroidTest{} |
| 1844 | m.AddProperties(&overridableAppProperties{}) |
| 1845 | m.AddProperties(&appTestProperties{}) |
| 1846 | |
| 1847 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 1848 | android.InitOverrideModule(m) |
| 1849 | return m |
| 1850 | } |
| 1851 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1852 | type UsesLibraryProperties struct { |
| 1853 | // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1854 | Uses_libs proptools.Configurable[[]string] |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1855 | |
| 1856 | // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file with |
| 1857 | // required=false. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1858 | Optional_uses_libs proptools.Configurable[[]string] |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1859 | |
| 1860 | // If true, the list of uses_libs and optional_uses_libs modules must match the AndroidManifest.xml file. Defaults |
| 1861 | // to true if either uses_libs or optional_uses_libs is set. Will unconditionally default to true in the future. |
| 1862 | Enforce_uses_libs *bool |
Ulya Trafimovich | 21a7375 | 2020-09-01 17:33:48 +0100 | [diff] [blame] | 1863 | |
Ulya Trafimovich | 54027b5 | 2020-09-09 14:08:23 +0100 | [diff] [blame] | 1864 | // Optional name of the <uses-library> provided by this module. This is needed for non-SDK |
| 1865 | // libraries, because SDK ones are automatically picked up by Soong. The <uses-library> name |
| 1866 | // normally is the same as the module name, but there are exceptions. |
| 1867 | Provides_uses_lib *string |
Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 1868 | |
| 1869 | // A list of shared library names to exclude from the classpath of the APK. Adding a library here |
| 1870 | // will prevent it from being used when precompiling the APK and prevent it from being implicitly |
| 1871 | // added to the APK's manifest's <uses-library> elements. |
| 1872 | // |
| 1873 | // Care must be taken when using this as it could result in runtime errors if the APK actually |
| 1874 | // uses classes provided by the library and which are not provided in any other way. |
| 1875 | // |
| 1876 | // This is primarily intended for use by various CTS tests that check the runtime handling of the |
| 1877 | // android.test.base shared library (and related libraries) but which depend on some common |
| 1878 | // libraries that depend on the android.test.base library. Without this those tests will end up |
| 1879 | // with a <uses-library android:name="android.test.base"/> in their manifest which would either |
| 1880 | // render the tests worthless (as they would be testing the wrong behavior), or would break the |
| 1881 | // test altogether by providing access to classes that the tests were not expecting. Those tests |
| 1882 | // provide the android.test.base statically and use jarjar to rename them so they do not collide |
| 1883 | // with the classes provided by the android.test.base library. |
| 1884 | Exclude_uses_libs []string |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 1885 | |
| 1886 | // The module names of optional uses-library libraries that are missing from the source tree. |
| 1887 | Missing_optional_uses_libs []string `blueprint:"mutated"` |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | // usesLibrary provides properties and helper functions for AndroidApp and AndroidAppImport to verify that the |
| 1891 | // <uses-library> tags that end up in the manifest of an APK match the ones known to the build system through the |
| 1892 | // uses_libs and optional_uses_libs properties. The build system's values are used by dexpreopt to preopt apps |
| 1893 | // with knowledge of their shared libraries. |
| 1894 | type usesLibrary struct { |
| 1895 | usesLibraryProperties UsesLibraryProperties |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 1896 | |
| 1897 | // Whether to enforce verify_uses_library check. |
| 1898 | enforce bool |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 1899 | |
| 1900 | // Whether dexpreopt should be disabled |
| 1901 | shouldDisableDexpreopt bool |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Colin Cross | 4a80a15 | 2022-12-21 21:51:52 -0800 | [diff] [blame] | 1904 | func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, addCompatDeps bool) { |
Jeongik Cha | 4b073cd | 2021-06-08 11:35:00 +0900 | [diff] [blame] | 1905 | if !ctx.Config().UnbundledBuild() || ctx.Config().UnbundledBuildImage() { |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1906 | ctx.AddVariationDependencies(nil, usesLibReqTag, u.usesLibraryProperties.Uses_libs.GetOrDefault(ctx, nil)...) |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 1907 | presentOptionalUsesLibs := u.presentOptionalUsesLibs(ctx) |
| 1908 | ctx.AddVariationDependencies(nil, usesLibOptTag, presentOptionalUsesLibs...) |
Colin Cross | 4a80a15 | 2022-12-21 21:51:52 -0800 | [diff] [blame] | 1909 | // Only add these extra dependencies if the module is an app that depends on framework |
| 1910 | // libs. This avoids creating a cyclic dependency: |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 1911 | // e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res. |
Colin Cross | 4a80a15 | 2022-12-21 21:51:52 -0800 | [diff] [blame] | 1912 | if addCompatDeps { |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 1913 | // Dexpreopt needs paths to the dex jars of these libraries in order to construct |
| 1914 | // class loader context for dex2oat. Add them as a dependency with a special tag. |
| 1915 | ctx.AddVariationDependencies(nil, usesLibCompat29ReqTag, dexpreopt.CompatUsesLibs29...) |
| 1916 | ctx.AddVariationDependencies(nil, usesLibCompat28OptTag, dexpreopt.OptionalCompatUsesLibs28...) |
| 1917 | ctx.AddVariationDependencies(nil, usesLibCompat30OptTag, dexpreopt.OptionalCompatUsesLibs30...) |
Colin Cross | 3245b2c | 2019-06-07 13:18:09 -0700 | [diff] [blame] | 1918 | } |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1919 | _, diff, _ := android.ListSetDifference(u.usesLibraryProperties.Optional_uses_libs.GetOrDefault(ctx, nil), presentOptionalUsesLibs) |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 1920 | u.usesLibraryProperties.Missing_optional_uses_libs = diff |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1921 | } else { |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1922 | ctx.AddVariationDependencies(nil, r8LibraryJarTag, u.usesLibraryProperties.Uses_libs.GetOrDefault(ctx, nil)...) |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1923 | ctx.AddVariationDependencies(nil, r8LibraryJarTag, u.presentOptionalUsesLibs(ctx)...) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | |
Jiakai Zhang | 4f65a03 | 2023-06-01 15:16:58 +0100 | [diff] [blame] | 1927 | // presentOptionalUsesLibs returns optional_uses_libs after filtering out libraries that don't exist in the source tree. |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1928 | func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []string { |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1929 | optionalUsesLibs := android.FilterListPred(u.usesLibraryProperties.Optional_uses_libs.GetOrDefault(ctx, nil), func(s string) bool { |
Jiakai Zhang | 4f65a03 | 2023-06-01 15:16:58 +0100 | [diff] [blame] | 1930 | exists := ctx.OtherModuleExists(s) |
Jiakai Zhang | 48203e3 | 2023-06-02 23:42:21 +0100 | [diff] [blame] | 1931 | if !exists && !android.InList(ctx.ModuleName(), ctx.Config().BuildWarningBadOptionalUsesLibsAllowlist()) { |
Jiakai Zhang | 4f65a03 | 2023-06-01 15:16:58 +0100 | [diff] [blame] | 1932 | fmt.Printf("Warning: Module '%s' depends on non-existing optional_uses_libs '%s'\n", ctx.ModuleName(), s) |
| 1933 | } |
| 1934 | return exists |
| 1935 | }) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1936 | return optionalUsesLibs |
| 1937 | } |
| 1938 | |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1939 | // Returns a map of module names of shared library dependencies to the paths to their dex jars on |
| 1940 | // host and on device. |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 1941 | func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext) dexpreopt.ClassLoaderContextMap { |
| 1942 | clcMap := make(dexpreopt.ClassLoaderContextMap) |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1943 | |
| 1944 | // Skip when UnbundledBuild() is true, but UnbundledBuildImage() is false. With |
| 1945 | // UnbundledBuildImage() it is necessary to generate dexpreopt.config for post-dexpreopting. |
| 1946 | if ctx.Config().UnbundledBuild() && !ctx.Config().UnbundledBuildImage() { |
| 1947 | return clcMap |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1950 | ctx.VisitDirectDeps(func(m android.Module) { |
| 1951 | tag, isUsesLibTag := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag) |
| 1952 | if !isUsesLibTag { |
| 1953 | return |
| 1954 | } |
| 1955 | |
Ulya Trafimovich | e14f80b | 2021-07-15 15:05:48 +0100 | [diff] [blame] | 1956 | dep := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(m)) |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1957 | |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 1958 | // Skip stub libraries. A dependency on the implementation library has been added earlier, |
| 1959 | // so it will be added to CLC, but the stub shouldn't be. Stub libraries can be distingushed |
| 1960 | // from implementation libraries by their name, which is different as it has a suffix. |
| 1961 | if comp, ok := m.(SdkLibraryComponentDependency); ok { |
| 1962 | if impl := comp.OptionalSdkLibraryImplementation(); impl != nil && *impl != dep { |
| 1963 | return |
| 1964 | } |
| 1965 | } |
| 1966 | |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1967 | if lib, ok := m.(UsesLibraryDependency); ok { |
Jihoon Kang | 98e9ac6 | 2024-09-25 23:42:30 +0000 | [diff] [blame] | 1968 | if _, ok := android.OtherModuleProvider(ctx, m, SdkLibraryInfoProvider); ok { |
| 1969 | // Skip java_sdk_library dependencies that provide stubs, but not an implementation. |
| 1970 | // This will be restricted to optional_uses_libs |
| 1971 | if tag == usesLibOptTag && lib.DexJarBuildPath(ctx).PathOrNil() == nil { |
| 1972 | u.shouldDisableDexpreopt = true |
| 1973 | return |
| 1974 | } |
| 1975 | } |
Ulya Trafimovich | e14f80b | 2021-07-15 15:05:48 +0100 | [diff] [blame] | 1976 | libName := dep |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1977 | if ulib, ok := m.(ProvidesUsesLib); ok && ulib.ProvidesUsesLib() != nil { |
Ulya Trafimovich | e14f80b | 2021-07-15 15:05:48 +0100 | [diff] [blame] | 1978 | libName = *ulib.ProvidesUsesLib() |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1979 | } |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 1980 | clcMap.AddContext(ctx, tag.sdkVersion, libName, tag.optional, |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 1981 | lib.DexJarBuildPath(ctx).PathOrNil(), lib.DexJarInstallPath(), |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1982 | lib.ClassLoaderContexts()) |
Ulya Trafimovich | 2444671 | 2021-07-15 14:59:34 +0100 | [diff] [blame] | 1983 | } else if ctx.Config().AllowMissingDependencies() { |
| 1984 | ctx.AddMissingDependencies([]string{dep}) |
| 1985 | } else { |
| 1986 | ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep) |
| 1987 | } |
| 1988 | }) |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 1989 | return clcMap |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | // enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs |
| 1993 | // properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true |
| 1994 | // unconditionally in the future. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 1995 | func (u *usesLibrary) enforceUsesLibraries(ctx android.ModuleContext) bool { |
| 1996 | defaultEnforceUsesLibs := len(u.usesLibraryProperties.Uses_libs.GetOrDefault(ctx, nil)) > 0 || |
| 1997 | len(u.usesLibraryProperties.Optional_uses_libs.GetOrDefault(ctx, nil)) > 0 |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 1998 | return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, u.enforce || defaultEnforceUsesLibs) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 2001 | // Freeze the value of `enforce_uses_libs` based on the current values of `uses_libs` and `optional_uses_libs`. |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 2002 | func (u *usesLibrary) freezeEnforceUsesLibraries(ctx android.ModuleContext) { |
| 2003 | enforce := u.enforceUsesLibraries(ctx) |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 2004 | u.usesLibraryProperties.Enforce_uses_libs = &enforce |
| 2005 | } |
| 2006 | |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2007 | // verifyUsesLibraries checks the <uses-library> tags in the manifest against the ones specified |
| 2008 | // in the `uses_libs`/`optional_uses_libs` properties. The input can be either an XML manifest, or |
| 2009 | // an APK with the manifest embedded in it (manifest_check will know which one it is by the file |
| 2010 | // extension: APKs are supposed to end with '.apk'). |
| 2011 | func (u *usesLibrary) verifyUsesLibraries(ctx android.ModuleContext, inputFile android.Path, |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2012 | outputFile android.WritablePath, classLoaderContexts *dexpreopt.ClassLoaderContextMap) android.Path { |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2013 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 2014 | statusFile := dexpreopt.UsesLibrariesStatusFile(ctx) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2015 | |
Ulya Trafimovich | 6e55ef1 | 2021-03-04 12:37:50 +0000 | [diff] [blame] | 2016 | // Disable verify_uses_libraries check if dexpreopt is globally disabled. Without dexpreopt the |
| 2017 | // check is not necessary, and although it is good to have, it is difficult to maintain on |
| 2018 | // non-linux build platforms where dexpreopt is generally disabled (the check may fail due to |
| 2019 | // various unrelated reasons, such as a failure to get manifest from an APK). |
Ulya Trafimovich | 39dd0a4 | 2021-03-29 14:57:34 +0100 | [diff] [blame] | 2020 | global := dexpreopt.GetGlobalConfig(ctx) |
Jiakai Zhang | 2398442 | 2023-11-09 16:47:04 +0000 | [diff] [blame] | 2021 | if global.DisablePreopt || global.OnlyPreoptArtBootImage { |
Ulya Trafimovich | a76d660 | 2021-03-16 15:34:50 +0000 | [diff] [blame] | 2022 | return inputFile |
Ulya Trafimovich | 6e55ef1 | 2021-03-04 12:37:50 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2025 | rule := android.NewRuleBuilder(pctx, ctx) |
| 2026 | cmd := rule.Command().BuiltTool("manifest_check"). |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2027 | Flag("--enforce-uses-libraries"). |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2028 | Input(inputFile). |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 2029 | FlagWithOutput("--enforce-uses-libraries-status ", statusFile). |
Saeid Farivar Asanjan | fd27c7c | 2022-08-08 20:21:26 +0000 | [diff] [blame] | 2030 | FlagWithInput("--aapt ", ctx.Config().HostToolPath(ctx, "aapt2")) |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2031 | |
| 2032 | if outputFile != nil { |
| 2033 | cmd.FlagWithOutput("-o ", outputFile) |
| 2034 | } |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2035 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 2036 | if dexpreopt.GetGlobalConfig(ctx).RelaxUsesLibraryCheck { |
| 2037 | cmd.Flag("--enforce-uses-libraries-relax") |
| 2038 | } |
| 2039 | |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2040 | requiredUsesLibs, optionalUsesLibs := classLoaderContexts.UsesLibs() |
| 2041 | for _, lib := range requiredUsesLibs { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2042 | cmd.FlagWithArg("--uses-library ", lib) |
| 2043 | } |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2044 | for _, lib := range optionalUsesLibs { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2045 | cmd.FlagWithArg("--optional-uses-library ", lib) |
| 2046 | } |
| 2047 | |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2048 | // Also add missing optional uses libs, as the manifest check expects them. |
| 2049 | // Note that what we add here are the module names of those missing libs, not library names, while |
| 2050 | // the manifest check actually expects library names. However, the case where a library is missing |
| 2051 | // and the module name != the library name is too rare for us to handle. |
| 2052 | for _, lib := range u.usesLibraryProperties.Missing_optional_uses_libs { |
| 2053 | cmd.FlagWithArg("--missing-optional-uses-library ", lib) |
| 2054 | } |
| 2055 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2056 | rule.Build("verify_uses_libraries", "verify <uses-library>") |
Ulya Trafimovich | a76d660 | 2021-03-16 15:34:50 +0000 | [diff] [blame] | 2057 | return outputFile |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2058 | } |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2059 | |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2060 | // verifyUsesLibrariesManifest checks the <uses-library> tags in an AndroidManifest.xml against |
| 2061 | // the build system and returns the path to a copy of the manifest. |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2062 | func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, manifest android.Path, |
| 2063 | classLoaderContexts *dexpreopt.ClassLoaderContextMap) android.Path { |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2064 | outputFile := android.PathForModuleOut(ctx, "manifest_check", "AndroidManifest.xml") |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2065 | return u.verifyUsesLibraries(ctx, manifest, outputFile, classLoaderContexts) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2068 | // verifyUsesLibrariesAPK checks the <uses-library> tags in the manifest of an APK against the build |
| 2069 | // system and returns the path to a copy of the APK. |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 2070 | func (u *usesLibrary) verifyUsesLibrariesAPK(ctx android.ModuleContext, apk android.Path, |
| 2071 | classLoaderContexts *dexpreopt.ClassLoaderContextMap) { |
| 2072 | u.verifyUsesLibraries(ctx, apk, nil, classLoaderContexts) // for APKs manifest_check does not write output file |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2073 | } |