Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | // This file contains the module implementations for android_app_import and android_test_import. |
| 18 | |
| 19 | import ( |
| 20 | "reflect" |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 21 | "strings" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 22 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
| 24 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 25 | "github.com/google/blueprint/proptools" |
| 26 | |
| 27 | "android/soong/android" |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 28 | "android/soong/provenance" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | RegisterAppImportBuildComponents(android.InitRegistrationContext) |
| 33 | |
| 34 | initAndroidAppImportVariantGroupTypes() |
| 35 | } |
| 36 | |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 37 | var ( |
| 38 | uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{ |
| 39 | Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + |
| 40 | `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` + |
| 41 | `; else cp -f $in $out; fi`, |
| 42 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 43 | Description: "Uncompress embedded JNI libs", |
| 44 | }) |
| 45 | |
Jim Tang | 6c4ecd0 | 2024-12-17 22:06:12 +0800 | [diff] [blame] | 46 | stripEmbeddedJniLibsUnusedArchRule = pctx.AndroidStaticRule("strip-embedded-jni-libs-from-unused-arch", blueprint.RuleParams{ |
| 47 | Command: `${config.Zip2ZipCmd} -i $in -o $out -x 'lib/**/*.so' $extraArgs`, |
| 48 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 49 | Description: "Remove all JNI libs from unused architectures", |
| 50 | }, "extraArgs") |
| 51 | |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 52 | uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{ |
| 53 | Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + |
| 54 | `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` + |
| 55 | `; else cp -f $in $out; fi`, |
| 56 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 57 | Description: "Uncompress dex files", |
| 58 | }) |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 59 | |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 60 | checkPresignedApkRule = pctx.AndroidStaticRule("check-presigned-apk", blueprint.RuleParams{ |
| 61 | Command: "build/soong/scripts/check_prebuilt_presigned_apk.py --aapt2 ${config.Aapt2Cmd} --zipalign ${config.ZipAlign} $extraArgs $in $out", |
| 62 | CommandDeps: []string{"build/soong/scripts/check_prebuilt_presigned_apk.py", "${config.Aapt2Cmd}", "${config.ZipAlign}"}, |
| 63 | Description: "Check presigned apk", |
| 64 | }, "extraArgs") |
Herbert Xue | 3b5672c | 2024-12-16 16:05:36 +0800 | [diff] [blame] | 65 | |
| 66 | extractApkRule = pctx.AndroidStaticRule("extract-apk", blueprint.RuleParams{ |
| 67 | Command: "unzip -p $in $extract_apk > $out", |
| 68 | Description: "Extract specific sub apk", |
| 69 | }, "extract_apk") |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 70 | ) |
| 71 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 72 | func RegisterAppImportBuildComponents(ctx android.RegistrationContext) { |
| 73 | ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) |
| 74 | ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 75 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 76 | ctx.BottomUp("disable_prebuilts_without_apk", disablePrebuiltsWithoutApkMutator) |
| 77 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | type AndroidAppImport struct { |
| 81 | android.ModuleBase |
| 82 | android.DefaultableModuleBase |
| 83 | android.ApexModuleBase |
| 84 | prebuilt android.Prebuilt |
| 85 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 86 | properties AndroidAppImportProperties |
| 87 | dpiVariants interface{} |
| 88 | archVariants interface{} |
| 89 | arch_dpiVariants interface{} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 90 | |
| 91 | outputFile android.Path |
| 92 | certificate Certificate |
| 93 | |
| 94 | dexpreopter |
| 95 | |
| 96 | usesLibrary usesLibrary |
| 97 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 98 | installPath android.InstallPath |
| 99 | |
| 100 | hideApexVariantFromMake bool |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 101 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 102 | provenanceMetaDataFile android.Path |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | type AndroidAppImportProperties struct { |
| 106 | // A prebuilt apk to import |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 107 | Apk proptools.Configurable[string] `android:"path,replace_instead_of_append"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 108 | |
| 109 | // The name of a certificate in the default certificate directory or an android_app_certificate |
| 110 | // module name in the form ":module". Should be empty if presigned or default_dev_cert is set. |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 111 | Certificate proptools.Configurable[string] `android:"replace_instead_of_append"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 112 | |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 113 | // Names of extra android_app_certificate modules to sign the apk with in the form ":module". |
| 114 | Additional_certificates []string |
| 115 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 116 | // Set this flag to true if the prebuilt apk is already signed. The certificate property must not |
| 117 | // be set for presigned modules. |
| 118 | Presigned *bool |
| 119 | |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 120 | // Name of the signing certificate lineage file or filegroup module. |
| 121 | Lineage *string `android:"path"` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 122 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 123 | // For overriding the --rotation-min-sdk-version property of apksig |
| 124 | RotationMinSdkVersion *string |
| 125 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 126 | // Sign with the default system dev certificate. Must be used judiciously. Most imported apps |
| 127 | // need to either specify a specific certificate or be presigned. |
| 128 | Default_dev_cert *bool |
| 129 | |
| 130 | // Specifies that this app should be installed to the priv-app directory, |
| 131 | // where the system will grant it additional privileges not available to |
| 132 | // normal apps. |
| 133 | Privileged *bool |
| 134 | |
| 135 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 136 | // (in Make or Soong). |
| 137 | // This does not completely prevent installation of the overridden binaries, but if both |
| 138 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 139 | // from PRODUCT_PACKAGES. |
| 140 | Overrides []string |
| 141 | |
| 142 | // Optional name for the installed app. If unspecified, it is derived from the module name. |
| 143 | Filename *string |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 144 | |
| 145 | // If set, create package-export.apk, which other packages can |
| 146 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
| 147 | Export_package_resources *bool |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 148 | |
| 149 | // Optional. Install to a subdirectory of the default install path for the module |
| 150 | Relative_install_path *string |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 151 | |
| 152 | // Whether the prebuilt apk can be installed without additional processing. Default is false. |
| 153 | Preprocessed *bool |
| 154 | |
| 155 | // Whether or not to skip checking the preprocessed apk for proper alignment and uncompressed |
| 156 | // JNI libs and dex files. Default is false |
| 157 | Skip_preprocessed_apk_checks *bool |
Spandan Das | efa1465 | 2024-02-27 18:19:16 +0000 | [diff] [blame] | 158 | |
| 159 | // Name of the source soong module that gets shadowed by this prebuilt |
| 160 | // If unspecified, follows the naming convention that the source module of |
| 161 | // the prebuilt is Name() without "prebuilt_" prefix |
| 162 | Source_module_name *string |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 163 | |
Jim Tang | 6c4ecd0 | 2024-12-17 22:06:12 +0800 | [diff] [blame] | 164 | // Whether stripping all libraries from unused architectures. |
| 165 | Strip_unused_jni_arch *bool |
| 166 | |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 167 | // Path to the .prebuilt_info file of the prebuilt app. |
| 168 | // In case of mainline modules, the .prebuilt_info file contains the build_id that was used |
| 169 | // to generate the prebuilt. |
| 170 | Prebuilt_info *string `android:"path"` |
Herbert Xue | 3b5672c | 2024-12-16 16:05:36 +0800 | [diff] [blame] | 171 | |
| 172 | // Path of extracted apk which is extracted from prebuilt apk. Use this extracted to import. |
| 173 | Extract_apk *string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | func (a *AndroidAppImport) IsInstallable() bool { |
| 177 | return true |
| 178 | } |
| 179 | |
| 180 | // Updates properties with variant-specific values. |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 181 | // This happens as a DefaultableHook instead of a LoadHook because we want to run it after |
| 182 | // soong config variables are applied. |
| 183 | func (a *AndroidAppImport) processVariants(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 184 | config := ctx.Config() |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 185 | dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName(DpiGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 186 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 187 | // Try DPI variant matches in the reverse-priority order so that the highest priority match |
| 188 | // overwrites everything else. |
| 189 | // TODO(jungjw): Can we optimize this by making it priority order? |
| 190 | for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- { |
| 191 | MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i]) |
| 192 | } |
| 193 | if config.ProductAAPTPreferredConfig() != "" { |
| 194 | MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig()) |
| 195 | } |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 196 | archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName(ArchGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 197 | archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType |
| 198 | MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name) |
| 199 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 200 | // Process "arch" includes "dpi_variants" |
| 201 | archStructPtr := reflect.ValueOf(a.arch_dpiVariants).Elem().FieldByName(ArchGroupName) |
| 202 | if archStruct := archStructPtr.Elem(); archStruct.IsValid() { |
| 203 | archPartPropsPtr := archStruct.FieldByName(proptools.FieldNameForProperty(archType.Name)) |
| 204 | if archPartProps := archPartPropsPtr.Elem(); archPartProps.IsValid() { |
| 205 | archDpiPropsPtr := archPartProps.FieldByName(DpiGroupName) |
| 206 | if archDpiProps := archDpiPropsPtr.Elem(); archDpiProps.IsValid() { |
| 207 | for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- { |
| 208 | MergePropertiesFromVariant(ctx, &a.properties, archDpiProps, config.ProductAAPTPrebuiltDPI()[i]) |
| 209 | } |
| 210 | if config.ProductAAPTPreferredConfig() != "" { |
| 211 | MergePropertiesFromVariant(ctx, &a.properties, archDpiProps, config.ProductAAPTPreferredConfig()) |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | func MergePropertiesFromVariant(ctx android.EarlyModuleContext, |
| 219 | dst interface{}, variantGroup reflect.Value, variant string) { |
| 220 | src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant)) |
| 221 | if !src.IsValid() { |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend) |
| 226 | if err != nil { |
| 227 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 228 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 229 | } else { |
| 230 | panic(err) |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 235 | // disablePrebuiltsWithoutApkMutator is a pre-arch mutator that disables AndroidAppImport or |
| 236 | // AndroidTestImport modules that don't have an apk set. We need this separate mutator instead |
| 237 | // of doing it in processVariants because processVariants is a defaultable hook, and configurable |
| 238 | // properties can only be evaluated after the defaults (and eventually, base configurabtion) |
| 239 | // mutators. |
| 240 | func disablePrebuiltsWithoutApkMutator(ctx android.BottomUpMutatorContext) { |
| 241 | switch a := ctx.Module().(type) { |
| 242 | case *AndroidAppImport: |
| 243 | if a.properties.Apk.GetOrDefault(ctx, "") == "" { |
| 244 | // Disable this module since the apk property is still empty after processing all |
| 245 | // matching variants. This likely means there is no matching variant, and the default |
| 246 | // variant doesn't have an apk property value either. |
| 247 | a.Disable() |
| 248 | } |
| 249 | case *AndroidTestImport: |
| 250 | if a.properties.Apk.GetOrDefault(ctx, "") == "" { |
| 251 | // Disable this module since the apk property is still empty after processing all |
| 252 | // matching variants. This likely means there is no matching variant, and the default |
| 253 | // variant doesn't have an apk property value either. |
| 254 | a.Disable() |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 259 | func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 260 | cert := android.SrcIsModule(a.properties.Certificate.GetOrDefault(ctx, "")) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 261 | if cert != "" { |
| 262 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 263 | } |
| 264 | |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 265 | for _, cert := range a.properties.Additional_certificates { |
| 266 | cert = android.SrcIsModule(cert) |
| 267 | if cert != "" { |
| 268 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 269 | } else { |
| 270 | ctx.PropertyErrorf("additional_certificates", |
| 271 | `must be names of android_app_certificate modules in the form ":module"`) |
| 272 | } |
| 273 | } |
| 274 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 275 | a.usesLibrary.deps(ctx, true) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | func (a *AndroidAppImport) uncompressEmbeddedJniLibs( |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 279 | ctx android.ModuleContext, inputPath android.Path, outputPath android.WritablePath) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 280 | // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing |
| 281 | // with them may invalidate pre-existing signature data. |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 282 | if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || Bool(a.properties.Preprocessed)) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 283 | ctx.Build(pctx, android.BuildParams{ |
| 284 | Rule: android.Cp, |
| 285 | Output: outputPath, |
| 286 | Input: inputPath, |
| 287 | }) |
| 288 | return |
| 289 | } |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 290 | |
| 291 | ctx.Build(pctx, android.BuildParams{ |
| 292 | Rule: uncompressEmbeddedJniLibsRule, |
| 293 | Input: inputPath, |
| 294 | Output: outputPath, |
| 295 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Herbert Xue | 3b5672c | 2024-12-16 16:05:36 +0800 | [diff] [blame] | 298 | func (a *AndroidAppImport) extractSubApk( |
| 299 | ctx android.ModuleContext, inputPath android.Path, outputPath android.WritablePath) { |
| 300 | extractApkPath := *a.properties.Extract_apk |
| 301 | ctx.Build(pctx, android.BuildParams{ |
| 302 | Rule: extractApkRule, |
| 303 | Input: inputPath, |
| 304 | Output: outputPath, |
| 305 | Args: map[string]string{ |
| 306 | "extract_apk": extractApkPath, |
| 307 | }, |
| 308 | }) |
| 309 | } |
| 310 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 311 | // Returns whether this module should have the dex file stored uncompressed in the APK. |
| 312 | func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 313 | if ctx.Config().UnbundledBuild() || proptools.Bool(a.properties.Preprocessed) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 314 | return false |
| 315 | } |
| 316 | |
Ulya Trafimovich | 0061c0d | 2021-09-01 15:40:38 +0100 | [diff] [blame] | 317 | // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false. |
| 318 | if a.Privileged() { |
| 319 | return ctx.Config().UncompressPrivAppDex() |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 322 | return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Jim Tang | 6c4ecd0 | 2024-12-17 22:06:12 +0800 | [diff] [blame] | 325 | func (a *AndroidAppImport) stripEmbeddedJniLibsUnusedArch( |
| 326 | ctx android.ModuleContext, inputPath android.Path, outputPath android.WritablePath) { |
| 327 | var wantedJniLibSlice []string |
| 328 | for _, target := range ctx.MultiTargets() { |
| 329 | supported_abis := target.Arch.Abi |
| 330 | for _, arch := range supported_abis { |
| 331 | wantedJniLibSlice = append(wantedJniLibSlice, " -X lib/"+arch+"/*.so") |
| 332 | } |
| 333 | } |
| 334 | wantedJniLibString := strings.Join(wantedJniLibSlice, " ") |
| 335 | ctx.Build(pctx, android.BuildParams{ |
| 336 | Rule: stripEmbeddedJniLibsUnusedArchRule, |
| 337 | Input: inputPath, |
| 338 | Output: outputPath, |
| 339 | Args: map[string]string{ |
| 340 | "extraArgs": wantedJniLibString, |
| 341 | }, |
| 342 | }) |
| 343 | } |
| 344 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 345 | func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 346 | a.generateAndroidBuildActions(ctx) |
| 347 | } |
| 348 | |
| 349 | func (a *AndroidAppImport) InstallApkName() string { |
| 350 | return a.BaseModuleName() |
| 351 | } |
| 352 | |
Spandan Das | efa1465 | 2024-02-27 18:19:16 +0000 | [diff] [blame] | 353 | func (a *AndroidAppImport) BaseModuleName() string { |
| 354 | return proptools.StringDefault(a.properties.Source_module_name, a.ModuleBase.Name()) |
| 355 | } |
| 356 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 357 | func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 358 | if a.Name() == "prebuilt_framework-res" { |
| 359 | ctx.ModuleErrorf("prebuilt_framework-res found. This used to have special handling in soong, but was removed due to prebuilt_framework-res no longer existing. This check is to ensure it doesn't come back without readding the special handling.") |
| 360 | } |
| 361 | |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 362 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 363 | if !apexInfo.IsForPlatform() { |
| 364 | a.hideApexVariantFromMake = true |
| 365 | } |
| 366 | |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 367 | if Bool(a.properties.Preprocessed) { |
| 368 | if a.properties.Presigned != nil && !*a.properties.Presigned { |
| 369 | ctx.ModuleErrorf("Setting preprocessed: true implies presigned: true, so you cannot set presigned to false") |
| 370 | } |
| 371 | t := true |
| 372 | a.properties.Presigned = &t |
| 373 | } |
| 374 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 375 | numCertPropsSet := 0 |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 376 | if a.properties.Certificate.GetOrDefault(ctx, "") != "" { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 377 | numCertPropsSet++ |
| 378 | } |
| 379 | if Bool(a.properties.Presigned) { |
| 380 | numCertPropsSet++ |
| 381 | } |
| 382 | if Bool(a.properties.Default_dev_cert) { |
| 383 | numCertPropsSet++ |
| 384 | } |
| 385 | if numCertPropsSet != 1 { |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 386 | ctx.ModuleErrorf("One and only one of certficate, presigned (implied by preprocessed), and default_dev_cert properties must be set") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 389 | // TODO: LOCAL_PACKAGE_SPLITS |
| 390 | |
| 391 | srcApk := a.prebuilt.SingleSourcePath(ctx) |
Herbert Xue | 3b5672c | 2024-12-16 16:05:36 +0800 | [diff] [blame] | 392 | if a.properties.Extract_apk != nil { |
| 393 | extract_apk := android.PathForModuleOut(ctx, "extract-apk", ctx.ModuleName()+".apk") |
| 394 | a.extractSubApk(ctx, srcApk, extract_apk) |
| 395 | srcApk = extract_apk |
| 396 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 397 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 398 | // TODO: Install or embed JNI libraries |
| 399 | |
| 400 | // Uncompress JNI libraries in the apk |
| 401 | jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk") |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 402 | a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 403 | |
Jim Tang | 6c4ecd0 | 2024-12-17 22:06:12 +0800 | [diff] [blame] | 404 | // Strip all embedded JNI libs and include only required ones accordingly to the module's compile_multilib |
| 405 | if Bool(a.properties.Strip_unused_jni_arch) { |
| 406 | jnisStripped := android.PathForModuleOut(ctx, "jnis-stripped", ctx.ModuleName()+".apk") |
| 407 | a.stripEmbeddedJniLibsUnusedArch(ctx, jnisUncompressed, jnisStripped) |
| 408 | jnisUncompressed = jnisStripped |
| 409 | } |
| 410 | |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 411 | var pathFragments []string |
| 412 | relInstallPath := String(a.properties.Relative_install_path) |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 413 | |
Cole Faust | d580613 | 2023-04-13 15:43:53 -0700 | [diff] [blame] | 414 | if Bool(a.properties.Privileged) { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 415 | pathFragments = []string{"priv-app", relInstallPath, a.BaseModuleName()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 416 | } else if ctx.InstallInTestcases() { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 417 | pathFragments = []string{relInstallPath, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 418 | } else { |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 419 | pathFragments = []string{"app", relInstallPath, a.BaseModuleName()} |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 422 | installDir := android.PathForModuleInstall(ctx, pathFragments...) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 423 | a.dexpreopter.isApp = true |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 424 | a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk") |
| 425 | a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned) |
| 426 | a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) |
| 427 | |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 428 | a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries(ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 429 | a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 430 | if a.usesLibrary.shouldDisableDexpreopt { |
| 431 | a.dexpreopter.disableDexpreopt() |
| 432 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 433 | |
Cole Faust | 64f2d84 | 2024-10-17 13:28:34 -0700 | [diff] [blame] | 434 | if a.usesLibrary.enforceUsesLibraries(ctx) { |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 435 | a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk, &a.dexpreopter.classLoaderContexts) |
Ulya Trafimovich | fe927a2 | 2021-02-26 14:36:48 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 438 | a.dexpreopter.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), jnisUncompressed) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 439 | if a.dexpreopter.uncompressedDex { |
| 440 | dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") |
Cole Faust | 4ec178c | 2023-01-13 12:03:38 -0800 | [diff] [blame] | 441 | ctx.Build(pctx, android.BuildParams{ |
| 442 | Rule: uncompressDexRule, |
| 443 | Input: jnisUncompressed, |
| 444 | Output: dexUncompressed, |
| 445 | }) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 446 | jnisUncompressed = dexUncompressed |
| 447 | } |
| 448 | |
| 449 | apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk") |
| 450 | |
| 451 | // TODO: Handle EXTERNAL |
| 452 | |
| 453 | // Sign or align the package if package has not been preprocessed |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 454 | |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 455 | if proptools.Bool(a.properties.Preprocessed) { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 456 | validationStamp := a.validatePresignedApk(ctx, srcApk) |
| 457 | output := android.PathForModuleOut(ctx, apkFilename) |
| 458 | ctx.Build(pctx, android.BuildParams{ |
| 459 | Rule: android.Cp, |
| 460 | Input: srcApk, |
| 461 | Output: output, |
| 462 | Validation: validationStamp, |
| 463 | }) |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 464 | a.outputFile = output |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 465 | a.certificate = PresignedCertificate |
| 466 | } else if !Bool(a.properties.Presigned) { |
| 467 | // If the certificate property is empty at this point, default_dev_cert must be set to true. |
| 468 | // Which makes processMainCert's behavior for the empty cert string WAI. |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 469 | _, _, certificates := collectAppDeps(ctx, a, false, false) |
Cole Faust | eb9c148 | 2024-11-18 16:49:19 -0800 | [diff] [blame] | 470 | a.certificate, certificates = processMainCert(a.ModuleBase, a.properties.Certificate.GetOrDefault(ctx, ""), certificates, ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 471 | signed := android.PathForModuleOut(ctx, "signed", apkFilename) |
| 472 | var lineageFile android.Path |
| 473 | if lineage := String(a.properties.Lineage); lineage != "" { |
| 474 | lineageFile = android.PathForModuleSrc(ctx, lineage) |
| 475 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 476 | |
| 477 | rotationMinSdkVersion := String(a.properties.RotationMinSdkVersion) |
| 478 | |
| 479 | SignAppPackage(ctx, signed, jnisUncompressed, certificates, nil, lineageFile, rotationMinSdkVersion) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 480 | a.outputFile = signed |
| 481 | } else { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 482 | validationStamp := a.validatePresignedApk(ctx, srcApk) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 483 | alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename) |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 484 | TransformZipAlign(ctx, alignedApk, jnisUncompressed, []android.Path{validationStamp}) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 485 | a.outputFile = alignedApk |
| 486 | a.certificate = PresignedCertificate |
| 487 | } |
| 488 | |
| 489 | // TODO: Optionally compress the output apk. |
| 490 | |
| 491 | if apexInfo.IsForPlatform() { |
| 492 | a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 493 | artifactPath := android.PathForModuleSrc(ctx, a.properties.Apk.GetOrDefault(ctx, "")) |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 494 | a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 497 | providePrebuiltInfo(ctx, |
| 498 | prebuiltInfoProps{ |
| 499 | baseModuleName: a.BaseModuleName(), |
| 500 | isPrebuilt: true, |
| 501 | prebuiltInfo: a.properties.Prebuilt_info, |
| 502 | }, |
| 503 | ) |
| 504 | |
mrziwang | 68786d8 | 2024-07-09 10:41:55 -0700 | [diff] [blame] | 505 | ctx.SetOutputFiles([]android.Path{a.outputFile}, "") |
| 506 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 507 | // TODO: androidmk converter jni libs |
| 508 | } |
| 509 | |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 510 | func (a *AndroidAppImport) validatePresignedApk(ctx android.ModuleContext, srcApk android.Path) android.Path { |
| 511 | stamp := android.PathForModuleOut(ctx, "validated-prebuilt", "check.stamp") |
| 512 | var extraArgs []string |
Cole Faust | 93b89b4 | 2023-07-20 17:31:16 -0700 | [diff] [blame] | 513 | if a.Privileged() { |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 514 | extraArgs = append(extraArgs, "--privileged") |
Rashid Zaman | 3bd2870 | 2024-07-23 17:23:05 -0700 | [diff] [blame] | 515 | if ctx.Config().UncompressPrivAppDex() { |
| 516 | extraArgs = append(extraArgs, "--uncompress-priv-app-dex") |
| 517 | } |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 518 | } |
| 519 | if proptools.Bool(a.properties.Skip_preprocessed_apk_checks) { |
| 520 | extraArgs = append(extraArgs, "--skip-preprocessed-apk-checks") |
| 521 | } |
| 522 | if proptools.Bool(a.properties.Preprocessed) { |
| 523 | extraArgs = append(extraArgs, "--preprocessed") |
Cole Faust | 93b89b4 | 2023-07-20 17:31:16 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Cole Faust | 2f1da16 | 2023-04-17 15:06:56 -0700 | [diff] [blame] | 526 | ctx.Build(pctx, android.BuildParams{ |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 527 | Rule: checkPresignedApkRule, |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 528 | Input: srcApk, |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 529 | Output: stamp, |
| 530 | Args: map[string]string{ |
| 531 | "extraArgs": strings.Join(extraArgs, " "), |
| 532 | }, |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 533 | }) |
Cole Faust | 9c5c09f | 2023-09-06 16:11:44 -0700 | [diff] [blame] | 534 | return stamp |
Cole Faust | 6158528 | 2023-07-14 16:23:39 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 537 | func (a *AndroidAppImport) Prebuilt() *android.Prebuilt { |
| 538 | return &a.prebuilt |
| 539 | } |
| 540 | |
| 541 | func (a *AndroidAppImport) Name() string { |
| 542 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 543 | } |
| 544 | |
| 545 | func (a *AndroidAppImport) OutputFile() android.Path { |
| 546 | return a.outputFile |
| 547 | } |
| 548 | |
| 549 | func (a *AndroidAppImport) JacocoReportClassesFile() android.Path { |
| 550 | return nil |
| 551 | } |
| 552 | |
| 553 | func (a *AndroidAppImport) Certificate() Certificate { |
| 554 | return a.certificate |
| 555 | } |
| 556 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 557 | func (a *AndroidAppImport) ProvenanceMetaDataFile() android.Path { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 558 | return a.provenanceMetaDataFile |
| 559 | } |
| 560 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 561 | func (a *AndroidAppImport) PrivAppAllowlist() android.OptionalPath { |
| 562 | return android.OptionalPath{} |
| 563 | } |
| 564 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 565 | const ( |
| 566 | ArchGroupName = "Arch" |
| 567 | DpiGroupName = "Dpi_variants" |
| 568 | ) |
| 569 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 570 | var dpiVariantGroupType reflect.Type |
| 571 | var archVariantGroupType reflect.Type |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 572 | var archdpiVariantGroupType reflect.Type |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 573 | var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"} |
| 574 | |
| 575 | func initAndroidAppImportVariantGroupTypes() { |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 576 | dpiVariantGroupType = createVariantGroupType(supportedDpis, DpiGroupName) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 577 | |
| 578 | archNames := make([]string, len(android.ArchTypeList())) |
| 579 | for i, archType := range android.ArchTypeList() { |
| 580 | archNames[i] = archType.Name |
| 581 | } |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 582 | archVariantGroupType = createVariantGroupType(archNames, ArchGroupName) |
| 583 | archdpiVariantGroupType = createArchDpiVariantGroupType(archNames, supportedDpis) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | // Populates all variant struct properties at creation time. |
| 587 | func (a *AndroidAppImport) populateAllVariantStructs() { |
| 588 | a.dpiVariants = reflect.New(dpiVariantGroupType).Interface() |
| 589 | a.AddProperties(a.dpiVariants) |
| 590 | |
| 591 | a.archVariants = reflect.New(archVariantGroupType).Interface() |
| 592 | a.AddProperties(a.archVariants) |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 593 | |
| 594 | a.arch_dpiVariants = reflect.New(archdpiVariantGroupType).Interface() |
| 595 | a.AddProperties(a.arch_dpiVariants) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | func (a *AndroidAppImport) Privileged() bool { |
| 599 | return Bool(a.properties.Privileged) |
| 600 | } |
| 601 | |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 602 | func (a *AndroidAppImport) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 603 | // android_app_import might have extra dependencies via uses_libs property. |
| 604 | // Don't track the dependency as we don't automatically add those libraries |
| 605 | // to the classpath. It should be explicitly added to java_libs property of APEX |
| 606 | return false |
| 607 | } |
| 608 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 609 | func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 610 | return android.SdkSpecPrivate |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 613 | func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 614 | return android.SdkSpecPrivate.ApiLevel |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | var _ android.ApexModule = (*AndroidAppImport)(nil) |
| 618 | |
| 619 | // Implements android.ApexModule |
| 620 | func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 621 | sdkVersion android.ApiLevel) error { |
| 622 | // Do not check for prebuilts against the min_sdk_version of enclosing APEX |
| 623 | return nil |
| 624 | } |
| 625 | |
| 626 | func createVariantGroupType(variants []string, variantGroupName string) reflect.Type { |
| 627 | props := reflect.TypeOf((*AndroidAppImportProperties)(nil)) |
| 628 | |
| 629 | variantFields := make([]reflect.StructField, len(variants)) |
| 630 | for i, variant := range variants { |
| 631 | variantFields[i] = reflect.StructField{ |
| 632 | Name: proptools.FieldNameForProperty(variant), |
| 633 | Type: props, |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | variantGroupStruct := reflect.StructOf(variantFields) |
| 638 | return reflect.StructOf([]reflect.StructField{ |
| 639 | { |
| 640 | Name: variantGroupName, |
| 641 | Type: variantGroupStruct, |
| 642 | }, |
| 643 | }) |
| 644 | } |
| 645 | |
Herbert Xue | 04354ae | 2024-01-29 13:57:51 +0800 | [diff] [blame] | 646 | func createArchDpiVariantGroupType(archNames []string, dpiNames []string) reflect.Type { |
| 647 | props := reflect.TypeOf((*AndroidAppImportProperties)(nil)) |
| 648 | |
| 649 | dpiVariantFields := make([]reflect.StructField, len(dpiNames)) |
| 650 | for i, variant_dpi := range dpiNames { |
| 651 | dpiVariantFields[i] = reflect.StructField{ |
| 652 | Name: proptools.FieldNameForProperty(variant_dpi), |
| 653 | Type: props, |
| 654 | } |
| 655 | } |
| 656 | dpiVariantGroupStruct := reflect.StructOf(dpiVariantFields) |
| 657 | dpi_struct := reflect.StructOf([]reflect.StructField{ |
| 658 | { |
| 659 | Name: DpiGroupName, |
| 660 | Type: reflect.PointerTo(dpiVariantGroupStruct), |
| 661 | }, |
| 662 | }) |
| 663 | |
| 664 | archVariantFields := make([]reflect.StructField, len(archNames)) |
| 665 | for i, variant_arch := range archNames { |
| 666 | archVariantFields[i] = reflect.StructField{ |
| 667 | Name: proptools.FieldNameForProperty(variant_arch), |
| 668 | Type: reflect.PointerTo(dpi_struct), |
| 669 | } |
| 670 | } |
| 671 | archVariantGroupStruct := reflect.StructOf(archVariantFields) |
| 672 | |
| 673 | return_struct := reflect.StructOf([]reflect.StructField{ |
| 674 | { |
| 675 | Name: ArchGroupName, |
| 676 | Type: reflect.PointerTo(archVariantGroupStruct), |
| 677 | }, |
| 678 | }) |
| 679 | return return_struct |
| 680 | } |
| 681 | |
Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 682 | func (a *AndroidAppImport) UsesLibrary() *usesLibrary { |
| 683 | return &a.usesLibrary |
| 684 | } |
| 685 | |
| 686 | var _ ModuleWithUsesLibrary = (*AndroidAppImport)(nil) |
| 687 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 688 | // android_app_import imports a prebuilt apk with additional processing specified in the module. |
| 689 | // DPI-specific apk source files can be specified using dpi_variants. Example: |
| 690 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 691 | // android_app_import { |
| 692 | // name: "example_import", |
| 693 | // apk: "prebuilts/example.apk", |
| 694 | // dpi_variants: { |
| 695 | // mdpi: { |
| 696 | // apk: "prebuilts/example_mdpi.apk", |
| 697 | // }, |
| 698 | // xhdpi: { |
| 699 | // apk: "prebuilts/example_xhdpi.apk", |
| 700 | // }, |
| 701 | // }, |
| 702 | // presigned: true, |
| 703 | // } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 704 | func AndroidAppImportFactory() android.Module { |
| 705 | module := &AndroidAppImport{} |
| 706 | module.AddProperties(&module.properties) |
| 707 | module.AddProperties(&module.dexpreoptProperties) |
| 708 | module.AddProperties(&module.usesLibrary.usesLibraryProperties) |
| 709 | module.populateAllVariantStructs() |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 710 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 711 | module.processVariants(ctx) |
| 712 | }) |
| 713 | |
| 714 | android.InitApexModule(module) |
| 715 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 716 | android.InitDefaultableModule(module) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 717 | android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 718 | |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 719 | module.usesLibrary.enforce = true |
| 720 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 721 | return module |
| 722 | } |
| 723 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 724 | type AndroidTestImport struct { |
| 725 | AndroidAppImport |
| 726 | |
Jiyong Park | 2f83b31 | 2022-10-20 20:18:35 +0900 | [diff] [blame] | 727 | testProperties struct { |
| 728 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 729 | // installed into. |
| 730 | Test_suites []string `android:"arch_variant"` |
| 731 | |
| 732 | // list of files or filegroup modules that provide data that should be installed alongside |
| 733 | // the test |
| 734 | Data []string `android:"path"` |
| 735 | |
| 736 | // Install the test into a folder named for the module in all test suites. |
| 737 | Per_testcase_directory *bool |
| 738 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 739 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 740 | data android.Paths |
| 741 | } |
| 742 | |
| 743 | func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 744 | a.generateAndroidBuildActions(ctx) |
| 745 | |
| 746 | a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) |
| 747 | } |
| 748 | |
| 749 | func (a *AndroidTestImport) InstallInTestcases() bool { |
| 750 | return true |
| 751 | } |
| 752 | |
| 753 | // android_test_import imports a prebuilt test apk with additional processing specified in the |
| 754 | // module. DPI or arch variant configurations can be made as with android_app_import. |
| 755 | func AndroidTestImportFactory() android.Module { |
| 756 | module := &AndroidTestImport{} |
| 757 | module.AddProperties(&module.properties) |
| 758 | module.AddProperties(&module.dexpreoptProperties) |
| 759 | module.AddProperties(&module.testProperties) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 760 | module.populateAllVariantStructs() |
Cole Faust | 97494b1 | 2024-01-12 14:02:47 -0800 | [diff] [blame] | 761 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 762 | module.processVariants(ctx) |
| 763 | }) |
| 764 | |
| 765 | module.dexpreopter.isTest = true |
| 766 | |
| 767 | android.InitApexModule(module) |
| 768 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 769 | android.InitDefaultableModule(module) |
Cole Faust | c71b175 | 2024-10-14 12:14:54 -0700 | [diff] [blame] | 770 | android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 771 | |
| 772 | return module |
| 773 | } |