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