Loading android/neverallow.go +10 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ func init() { AddNeverAllowRules(createMediaRules()...) AddNeverAllowRules(createJavaDeviceForHostRules()...) AddNeverAllowRules(createCcSdkVariantRules()...) AddNeverAllowRules(createUncompressDexRules()...) } // Add a NeverAllow rule to the set of rules to apply. Loading Loading @@ -210,6 +211,15 @@ func createCcSdkVariantRules() []Rule { } } func createUncompressDexRules() []Rule { return []Rule{ NeverAllow(). NotIn("art"). WithMatcher("uncompress_dex", isSetMatcherInstance). Because("uncompress_dex is only allowed for certain jars for test in art."), } } func neverallowMutator(ctx BottomUpMutatorContext) { m, ok := ctx.Module().(Module) if !ok { Loading android/neverallow_test.go +26 −2 Original line number Diff line number Diff line Loading @@ -303,6 +303,29 @@ var neverallowTests = []struct { `module "outside_whitelist": violates neverallow`, }, }, { name: "uncompress_dex inside art", fs: map[string][]byte{ "art/Android.bp": []byte(` java_library { name: "inside_art_libraries", uncompress_dex: true, }`), }, }, { name: "uncompress_dex outside art", fs: map[string][]byte{ "other/Android.bp": []byte(` java_library { name: "outside_art_libraries", uncompress_dex: true, }`), }, expectedErrors: []string{ "module \"outside_art_libraries\": violates neverallow", }, }, } func TestNeverallow(t *testing.T) { Loading Loading @@ -398,6 +421,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { type mockJavaLibraryProperties struct { Libs []string Sdk_version *string Uncompress_dex *bool } type mockJavaLibraryModule struct { Loading java/app.go +5 −4 Original line number Diff line number Diff line Loading @@ -540,16 +540,17 @@ 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.uncompressedDex = a.shouldUncompressDex(ctx) if a.deviceProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx)) } a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx) a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx) a.dexpreopter.manifestFile = a.mergedManifestFile a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) } Loading java/app_test.go +26 −0 Original line number Diff line number Diff line Loading @@ -2706,6 +2706,32 @@ func TestUncompressDex(t *testing.T) { uncompressedPlatform: true, uncompressedUnbundled: true, }, { name: "normal_uncompress_dex_true", bp: ` android_app { name: "foo", srcs: ["a.java"], sdk_version: "current", uncompress_dex: true, } `, uncompressedPlatform: true, uncompressedUnbundled: true, }, { name: "normal_uncompress_dex_false", bp: ` android_app { name: "foo", srcs: ["a.java"], sdk_version: "current", uncompress_dex: false, } `, uncompressedPlatform: false, uncompressedUnbundled: false, }, } test := func(t *testing.T, bp string, want bool, unbundled bool) { Loading java/dex.go +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" "android/soong/android" ) Loading Loading @@ -177,7 +178,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, outDir := android.PathForModuleOut(ctx, "dex") zipFlags := "--ignore_missing_files" if j.deviceProperties.UncompressDex { if proptools.Bool(j.deviceProperties.Uncompress_dex) { zipFlags += " -L 0" } Loading Loading @@ -214,7 +215,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, }, }) } if j.deviceProperties.UncompressDex { if proptools.Bool(j.deviceProperties.Uncompress_dex) { alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName) TransformZipAlign(ctx, alignedJavalibJar, javalibJar) javalibJar = alignedJavalibJar Loading Loading
android/neverallow.go +10 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ func init() { AddNeverAllowRules(createMediaRules()...) AddNeverAllowRules(createJavaDeviceForHostRules()...) AddNeverAllowRules(createCcSdkVariantRules()...) AddNeverAllowRules(createUncompressDexRules()...) } // Add a NeverAllow rule to the set of rules to apply. Loading Loading @@ -210,6 +211,15 @@ func createCcSdkVariantRules() []Rule { } } func createUncompressDexRules() []Rule { return []Rule{ NeverAllow(). NotIn("art"). WithMatcher("uncompress_dex", isSetMatcherInstance). Because("uncompress_dex is only allowed for certain jars for test in art."), } } func neverallowMutator(ctx BottomUpMutatorContext) { m, ok := ctx.Module().(Module) if !ok { Loading
android/neverallow_test.go +26 −2 Original line number Diff line number Diff line Loading @@ -303,6 +303,29 @@ var neverallowTests = []struct { `module "outside_whitelist": violates neverallow`, }, }, { name: "uncompress_dex inside art", fs: map[string][]byte{ "art/Android.bp": []byte(` java_library { name: "inside_art_libraries", uncompress_dex: true, }`), }, }, { name: "uncompress_dex outside art", fs: map[string][]byte{ "other/Android.bp": []byte(` java_library { name: "outside_art_libraries", uncompress_dex: true, }`), }, expectedErrors: []string{ "module \"outside_art_libraries\": violates neverallow", }, }, } func TestNeverallow(t *testing.T) { Loading Loading @@ -398,6 +421,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { type mockJavaLibraryProperties struct { Libs []string Sdk_version *string Uncompress_dex *bool } type mockJavaLibraryModule struct { Loading
java/app.go +5 −4 Original line number Diff line number Diff line Loading @@ -540,16 +540,17 @@ 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.uncompressedDex = a.shouldUncompressDex(ctx) if a.deviceProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx)) } a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx) a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx) a.dexpreopter.manifestFile = a.mergedManifestFile a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) } Loading
java/app_test.go +26 −0 Original line number Diff line number Diff line Loading @@ -2706,6 +2706,32 @@ func TestUncompressDex(t *testing.T) { uncompressedPlatform: true, uncompressedUnbundled: true, }, { name: "normal_uncompress_dex_true", bp: ` android_app { name: "foo", srcs: ["a.java"], sdk_version: "current", uncompress_dex: true, } `, uncompressedPlatform: true, uncompressedUnbundled: true, }, { name: "normal_uncompress_dex_false", bp: ` android_app { name: "foo", srcs: ["a.java"], sdk_version: "current", uncompress_dex: false, } `, uncompressedPlatform: false, uncompressedUnbundled: false, }, } test := func(t *testing.T, bp string, want bool, unbundled bool) { Loading
java/dex.go +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" "android/soong/android" ) Loading Loading @@ -177,7 +178,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, outDir := android.PathForModuleOut(ctx, "dex") zipFlags := "--ignore_missing_files" if j.deviceProperties.UncompressDex { if proptools.Bool(j.deviceProperties.Uncompress_dex) { zipFlags += " -L 0" } Loading Loading @@ -214,7 +215,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, }, }) } if j.deviceProperties.UncompressDex { if proptools.Bool(j.deviceProperties.Uncompress_dex) { alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName) TransformZipAlign(ctx, alignedJavalibJar, javalibJar) javalibJar = alignedJavalibJar Loading