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