Merge "Uncompress dex in unbundled privileged apps"
This commit is contained in:
@@ -216,6 +216,7 @@ func TestConfig(buildDir string, env map[string]string) Config {
|
|||||||
AAPTPreferredConfig: stringPtr("xhdpi"),
|
AAPTPreferredConfig: stringPtr("xhdpi"),
|
||||||
AAPTCharacteristics: stringPtr("nosdcard"),
|
AAPTCharacteristics: stringPtr("nosdcard"),
|
||||||
AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
|
AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
|
||||||
|
UncompressPrivAppDex: boolPtr(true),
|
||||||
},
|
},
|
||||||
|
|
||||||
buildDir: buildDir,
|
buildDir: buildDir,
|
||||||
|
11
java/app.go
11
java/app.go
@@ -229,15 +229,16 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Config().UnbundledBuild() {
|
// Uncompress dex in APKs of privileged apps (even for unbundled builds, they may
|
||||||
return false
|
// be preinstalled as prebuilts).
|
||||||
}
|
|
||||||
|
|
||||||
// Uncompress dex in APKs of privileged apps
|
|
||||||
if ctx.Config().UncompressPrivAppDex() && Bool(a.appProperties.Privileged) {
|
if ctx.Config().UncompressPrivAppDex() && Bool(a.appProperties.Privileged) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Config().UnbundledBuild() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return shouldUncompressDex(ctx, &a.dexpreopter)
|
return shouldUncompressDex(ctx, &a.dexpreopter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1491,3 +1491,86 @@ func TestEmbedNotice(t *testing.T) {
|
|||||||
t.Errorf("mergeNotices shouldn't have run for baz")
|
t.Errorf("mergeNotices shouldn't have run for baz")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUncompressDex(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
bp string
|
||||||
|
|
||||||
|
uncompressedPlatform bool
|
||||||
|
uncompressedUnbundled bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "normal",
|
||||||
|
bp: `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
uncompressedPlatform: true,
|
||||||
|
uncompressedUnbundled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "use_embedded_dex",
|
||||||
|
bp: `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
use_embedded_dex: true,
|
||||||
|
srcs: ["a.java"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
uncompressedPlatform: true,
|
||||||
|
uncompressedUnbundled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "privileged",
|
||||||
|
bp: `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
privileged: true,
|
||||||
|
srcs: ["a.java"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
uncompressedPlatform: true,
|
||||||
|
uncompressedUnbundled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
test := func(t *testing.T, bp string, want bool, unbundled bool) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
config := testConfig(nil)
|
||||||
|
if unbundled {
|
||||||
|
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := testAppContext(config, bp, nil)
|
||||||
|
|
||||||
|
run(t, ctx, config)
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
dex := foo.Rule("r8")
|
||||||
|
uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0")
|
||||||
|
aligned := foo.MaybeRule("zipalign").Rule != nil
|
||||||
|
|
||||||
|
if uncompressedInDexJar != want {
|
||||||
|
t.Errorf("want uncompressed in dex %v, got %v", want, uncompressedInDexJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aligned != want {
|
||||||
|
t.Errorf("want aligned %v, got %v", want, aligned)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testCases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Run("platform", func(t *testing.T) {
|
||||||
|
test(t, tt.bp, tt.uncompressedPlatform, false)
|
||||||
|
})
|
||||||
|
t.Run("unbundled", func(t *testing.T) {
|
||||||
|
test(t, tt.bp, tt.uncompressedUnbundled, true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user