aboutsummaryrefslogtreecommitdiffstats
path: root/java/app.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-10-05 14:20:06 -0700
committerColin Cross <ccross@android.com>2018-10-25 17:47:12 +0000
commit5a0dcd5acf0788a8bd97d903a40b5d7931e5b2cd (patch)
tree5d2f03061e9732d204d272c258d11b42b6a3621e /java/app.go
parent1e30905f6525b35f565b5b0bf395f7279658a6b0 (diff)
downloadandroid_build_soong-5a0dcd5acf0788a8bd97d903a40b5d7931e5b2cd.tar.gz
android_build_soong-5a0dcd5acf0788a8bd97d903a40b5d7931e5b2cd.tar.bz2
android_build_soong-5a0dcd5acf0788a8bd97d903a40b5d7931e5b2cd.zip
Store dex files uncompressed and unstripped in privileged APKs
Privileged APKs need to store their dex files uncompressed so they can be verified and mapped directly out of the APK. Also track whether the module will be dexpreopted or not in order to determine if the dex file should be stripped before signing. Test: SystemUI.apk contains an uncompressed dex file Change-Id: I4dca86c7f8778595882405b34adcf2a7bae03c67
Diffstat (limited to 'java/app.go')
-rw-r--r--java/app.go54
1 files changed, 50 insertions, 4 deletions
diff --git a/java/app.go b/java/app.go
index 5d25dcf1..d1b04c3c 100644
--- a/java/app.go
+++ b/java/app.go
@@ -67,7 +67,9 @@ type appProperties struct {
// list of native libraries that will be provided in or alongside the resulting jar
Jni_libs []string `android:"arch_variant"`
- EmbedJNI bool `blueprint:"mutated"`
+ AllowDexPreopt bool `blueprint:"mutated"`
+ EmbedJNI bool `blueprint:"mutated"`
+ StripDex bool `blueprint:"mutated"`
}
type AndroidApp struct {
@@ -139,6 +141,42 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.generateAndroidBuildActions(ctx)
}
+// Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If
+// stripped, the code will still be present on the device in the dexpreopted files.
+// This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed
+// or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed
+// or removed at installation time in Make.
+func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) {
+ if ctx.Config().UnbundledBuild() {
+ return false, false
+ }
+
+ strip = ctx.Config().DefaultStripDex()
+ // TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor)
+ // TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent
+ // TODO(ccross): don't strip dex on modules that are preopted to system_other
+
+ // Uncompress dex in APKs of privileged apps, and modules used by privileged apps.
+ if ctx.Config().UncompressPrivAppDex() &&
+ (Bool(a.appProperties.Privileged) ||
+ inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) {
+
+ uncompress = true
+ // If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK
+ // instead of copying it into the odex file.
+ strip = false
+ }
+
+ // If dexpreopt is disabled, don't strip the dex file
+ if !a.appProperties.AllowDexPreopt ||
+ !BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) ||
+ ctx.Config().DisableDexPreopt(ctx.ModuleName()) {
+ strip = false
+ }
+
+ return uncompress, strip
+}
+
func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
linkFlags := append([]string(nil), a.extraLinkFlags...)
@@ -184,11 +222,16 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
+ a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx)
+
if ctx.ModuleName() != "framework-res" {
a.Module.compile(ctx, a.aaptSrcJar)
}
+ dexJarFile := a.dexJarFile
- packageFile := android.PathForModuleOut(ctx, "package.apk")
+ if a.appProperties.StripDex {
+ dexJarFile = nil
+ }
var certificates []certificate
@@ -226,8 +269,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
certificates = append([]certificate{a.certificate}, certificateDeps...)
- CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, a.outputFile, certificates)
-
+ packageFile := android.PathForModuleOut(ctx, "package.apk")
+ CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates)
a.outputFile = packageFile
if ctx.ModuleName() == "framework-res" {
@@ -284,6 +327,7 @@ func AndroidAppFactory() android.Module {
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
+ module.appProperties.AllowDexPreopt = true
module.AddProperties(
&module.Module.properties,
@@ -345,6 +389,7 @@ func AndroidTestFactory() android.Module {
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
module.appProperties.EmbedJNI = true
+ module.appProperties.AllowDexPreopt = false
module.AddProperties(
&module.Module.properties,
@@ -379,6 +424,7 @@ func AndroidTestHelperAppFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true)
module.appProperties.EmbedJNI = true
+ module.appProperties.AllowDexPreopt = false
module.AddProperties(
&module.Module.properties,