From 55f72d706d9e70691c9b0fce947fb03f9e5ba7f0 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 1 Sep 2021 14:13:57 +0100 Subject: [PATCH 1/2] Add tests for uncompressed dex for `android_app_import`. Some of the test cases for privileged apps currently produce incorrect results (e.g. with DONT_UNCOMPRESS_PRIV_APPS_DEXS := true); they are marked with TODO and will be fixed in a follow-up CL. Bug: 194504107 Test: m nothing Change-Id: Ic0cd24113a27850a967afa0b3deb4a6324f95347 --- java/app_import_test.go | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/java/app_import_test.go b/java/app_import_test.go index 024a3df51..49d717daf 100644 --- a/java/app_import_test.go +++ b/java/app_import_test.go @@ -15,6 +15,7 @@ package java import ( + "fmt" "reflect" "regexp" "strings" @@ -656,3 +657,74 @@ func TestAndroidTestImport_Preprocessed(t *testing.T) { } } } + +func TestAndroidTestImport_UncompressDex(t *testing.T) { + testCases := []struct { + name string + bp string + }{ + { + name: "normal", + bp: ` + android_app_import { + name: "foo", + presigned: true, + apk: "prebuilts/apk/app.apk", + } + `, + }, + { + name: "privileged", + bp: ` + android_app_import { + name: "foo", + presigned: true, + privileged: true, + apk: "prebuilts/apk/app.apk", + } + `, + }, + } + + test := func(t *testing.T, bp string, unbundled bool, dontUncompressPrivAppDexs bool) { + t.Helper() + + result := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + if unbundled { + variables.Unbundled_build = proptools.BoolPtr(true) + } + variables.UncompressPrivAppDex = proptools.BoolPtr(!dontUncompressPrivAppDexs) + }), + ).RunTestWithBp(t, bp) + + foo := result.ModuleForTests("foo", "android_common") + actual := foo.MaybeRule("uncompress-dex").Rule != nil + + expect := !unbundled + if strings.Contains(bp, "privileged: true") { + if dontUncompressPrivAppDexs { + // TODO(b/194504107): DONT_UNCOMPRESS_PRIV_APPS_DEXS should disable uncompression of priv-apps no matter what. + // expect = false + } else { + // TODO(b/194504107): shouldn't priv-apps be always uncompressed unless DONT_UNCOMPRESS_PRIV_APPS_DEXS is true? + // expect = true + } + } + + android.AssertBoolEquals(t, "uncompress dex", expect, actual) + } + + for _, unbundled := range []bool{false, true} { + for _, dontUncompressPrivAppDexs := range []bool{false, true} { + for _, tt := range testCases { + name := fmt.Sprintf("%s,unbundled:%t,dontUncompressPrivAppDexs:%t", + tt.name, unbundled, dontUncompressPrivAppDexs) + t.Run(name, func(t *testing.T) { + test(t, tt.bp, unbundled, dontUncompressPrivAppDexs) + }) + } + } + } +} From 0061c0d1daad8123fd3eea87dc17624610a49040 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 1 Sep 2021 15:40:38 +0100 Subject: [PATCH 2/2] Fix DONT_UNCOMPRESS_PRIV_APPS_DEXS for `android_app_import`. Don't uncompress priv-app dex for `android_app_import` if DONT_UNCOMPRESS_PRIV_APPS_DEXS is true. Update expected test results. Bug: 194504107 Test: m nothing Change-Id: I4e7aa1a3deea856f388ae5ecd9292301f8a09a2f --- java/app_import.go | 6 +++--- java/app_import_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/app_import.go b/java/app_import.go index b5a608412..3e5f972a4 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -204,9 +204,9 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { return false } - // Uncompress dex in APKs of privileged apps - if ctx.Config().UncompressPrivAppDex() && a.Privileged() { - return true + // Uncompress dex in APKs of priv-apps if and only if DONT_UNCOMPRESS_PRIV_APPS_DEXS is false. + if a.Privileged() { + return ctx.Config().UncompressPrivAppDex() } return shouldUncompressDex(ctx, &a.dexpreopter) diff --git a/java/app_import_test.go b/java/app_import_test.go index 49d717daf..efa52c178 100644 --- a/java/app_import_test.go +++ b/java/app_import_test.go @@ -705,10 +705,10 @@ func TestAndroidTestImport_UncompressDex(t *testing.T) { expect := !unbundled if strings.Contains(bp, "privileged: true") { if dontUncompressPrivAppDexs { - // TODO(b/194504107): DONT_UNCOMPRESS_PRIV_APPS_DEXS should disable uncompression of priv-apps no matter what. - // expect = false + expect = false } else { - // TODO(b/194504107): shouldn't priv-apps be always uncompressed unless DONT_UNCOMPRESS_PRIV_APPS_DEXS is true? + // TODO(b/194504107): shouldn't priv-apps be always uncompressed unless + // DONT_UNCOMPRESS_PRIV_APPS_DEXS is true (regardless of unbundling)? // expect = true } }