From 67e8ec1973700bbdbc4cd68b3493d56d270ca377 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 11 Feb 2019 19:30:46 +0000 Subject: [PATCH] Revert "Never strip and store dex files uncompressed when they are preopted on system." This reverts commit 4bb0106759a9a84dff4e7b6a6d207097365f8230. Reason for revert: b/123436620 Change-Id: Ia7595ace4b76abaa99dbb651e7d2f088dec5bad9 --- dexpreopt/config.go | 3 +-- dexpreopt/dexpreopt.go | 13 +++---------- dexpreopt/dexpreopt_test.go | 18 ------------------ java/app.go | 17 +++-------------- java/dexpreopt.go | 19 +++++-------------- java/java.go | 17 +++++++---------- 6 files changed, 19 insertions(+), 68 deletions(-) diff --git a/dexpreopt/config.go b/dexpreopt/config.go index 9c122e60a..319e36e4d 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go @@ -46,8 +46,7 @@ type GlobalConfig struct { DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars - GenerateDMFiles bool // generate Dex Metadata files - NeverAllowStripping bool // whether stripping should not be done - used as build time check to make sure dex files are always available + GenerateDMFiles bool // generate Dex Metadata files NoDebugInfo bool // don't generate debug info by default AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true) diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go index a86e4d13a..c38fbff9c 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -68,9 +68,6 @@ func GenerateStripRule(global GlobalConfig, module ModuleConfig) (rule *android. strip := shouldStripDex(module, global) if strip { - if global.NeverAllowStripping { - panic(fmt.Errorf("Stripping requested on %q, though the product does not allow it", module.DexLocation)) - } // Only strips if the dex files are not already uncompressed rule.Command(). Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, module.StripInputPath). @@ -502,7 +499,7 @@ func shouldGenerateDM(module ModuleConfig, global GlobalConfig) bool { contains(module.PreoptFlags, "--compiler-filter=verify") } -func OdexOnSystemOtherByName(name string, dexLocation string, global GlobalConfig) bool { +func odexOnSystemOther(module ModuleConfig, global GlobalConfig) bool { if !global.HasSystemOther { return false } @@ -511,12 +508,12 @@ func OdexOnSystemOtherByName(name string, dexLocation string, global GlobalConfi return false } - if contains(global.SpeedApps, name) || contains(global.SystemServerApps, name) { + if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) { return false } for _, f := range global.PatternsOnSystemOther { - if makefileMatch(filepath.Join(SystemPartition, f), dexLocation) { + if makefileMatch(filepath.Join(SystemPartition, f), module.DexLocation) { return true } } @@ -524,10 +521,6 @@ func OdexOnSystemOtherByName(name string, dexLocation string, global GlobalConfi return false } -func odexOnSystemOther(module ModuleConfig, global GlobalConfig) bool { - return OdexOnSystemOtherByName(module.Name, module.DexLocation, global) -} - func pathForLibrary(module ModuleConfig, lib string) string { path := module.LibraryPaths[lib] if path == "" { diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go index 43185656a..d949852f6 100644 --- a/dexpreopt/dexpreopt_test.go +++ b/dexpreopt/dexpreopt_test.go @@ -36,7 +36,6 @@ var testGlobalConfig = GlobalConfig{ DefaultCompilerFilter: "", SystemServerCompilerFilter: "", GenerateDMFiles: false, - NeverAllowStripping: false, NoDebugInfo: false, AlwaysSystemServerDebugInfo: false, NeverSystemServerDebugInfo: false, @@ -111,23 +110,6 @@ func TestDexPreopt(t *testing.T) { } } -func TestDexPreoptStrip(t *testing.T) { - // Test that we panic if we strip in a configuration where stripping is not allowed. - global, module := testGlobalConfig, testModuleConfig - - global.NeverAllowStripping = true - module.NoStripping = false - module.Name = "test" - module.DexLocation = "/system/app/test/test.apk" - module.BuildPath = "out/test/test.apk" - module.Archs = []string{"arm"} - - _, err := GenerateStripRule(global, module) - if err == nil { - t.Errorf("Expected an error when calling GenerateStripRule on a stripped module") - } -} - func TestDexPreoptSystemOther(t *testing.T) { global, module := testGlobalConfig, testModuleConfig diff --git a/java/app.go b/java/app.go index 96d89f5f3..47f4f0d80 100644 --- a/java/app.go +++ b/java/app.go @@ -162,18 +162,9 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { } // Uncompress dex in APKs of privileged apps, and modules used by privileged apps. - if ctx.Config().UncompressPrivAppDex() && + return ctx.Config().UncompressPrivAppDex() && (Bool(a.appProperties.Privileged) || - inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { - return true - } - - // Uncompress if the dex files is preopted on /system. - if !a.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, a.dexpreopter.installPath)) { - return true - } - - return false + inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) } func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { @@ -232,6 +223,7 @@ func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) { } func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { + a.deviceProperties.UncompressDex = a.shouldUncompressDex(ctx) var installDir string if ctx.ModuleName() == "framework-res" { @@ -243,9 +235,6 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { installDir = filepath.Join("app", a.installApkName) } a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") - a.dexpreopter.isInstallable = Bool(a.properties.Installable) - a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) - a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index c55edfc89..55662cf41 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -83,7 +83,11 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool { var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig") -func getGlobalConfig(ctx android.ModuleContext) dexpreopt.GlobalConfig { +func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath { + if d.dexpreoptDisabled(ctx) { + return dexJarFile + } + globalConfig := ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} { if f := ctx.Config().DexpreoptGlobalConfig(); f != "" { ctx.AddNinjaFileDeps(f) @@ -95,19 +99,6 @@ func getGlobalConfig(ctx android.ModuleContext) dexpreopt.GlobalConfig { } return dexpreopt.GlobalConfig{} }).(dexpreopt.GlobalConfig) - return globalConfig -} - -func odexOnSystemOther(ctx android.ModuleContext, installPath android.OutputPath) bool { - return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), getGlobalConfig(ctx)) -} - -func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath { - if d.dexpreoptDisabled(ctx) { - return dexJarFile - } - - globalConfig := getGlobalConfig(ctx) var archs []string for _, a := range ctx.MultiTargets() { diff --git a/java/java.go b/java/java.go index 34e06d63a..3d7d6ad8d 100644 --- a/java/java.go +++ b/java/java.go @@ -1239,6 +1239,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.dexJarFile = dexOutputFile // Dexpreopting + j.dexpreopter.isInstallable = Bool(j.properties.Installable) + j.dexpreopter.uncompressedDex = j.deviceProperties.UncompressDex dexOutputFile = j.dexpreopt(ctx, dexOutputFile) j.maybeStrippedDexJarFile = dexOutputFile @@ -1415,13 +1417,10 @@ type Library struct { } func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool { - // Store uncompressed (and do not strip) dex files from boot class path jars. - if inList(ctx.ModuleName(), ctx.Config().BootJars()) { - return true - } - - // Store uncompressed dex files that are preopted on /system. - if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) { + // Store uncompressed (and do not strip) dex files from boot class path jars that are + // in an apex. + if inList(ctx.ModuleName(), ctx.Config().BootJars()) && + android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { return true } if ctx.Config().UncompressPrivAppDex() && @@ -1435,9 +1434,7 @@ func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool { func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary - j.dexpreopter.isInstallable = Bool(j.properties.Installable) - j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx) - j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex + j.deviceProperties.UncompressDex = j.shouldUncompressDex(ctx) j.compile(ctx) if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {