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