Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c6d250c authored by Colin Cross's avatar Colin Cross
Browse files

Allow modules to disable stripping when dexpreopting

Add a no_stripping property and pass it to dexpreopt to disable
stripping for a module.

Bug: 122610462
Test: dexpreopt_test.go
Change-Id: I5a4b005633bb8b1ea373e9eeb420aa0999de17ab
parent ed918b77
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ type ModuleConfig struct {

	PresignedPrebuilt bool

	NoStripping     bool
	StripInputPath  string
	StripOutputPath string
}
+4 −0
Original line number Diff line number Diff line
@@ -454,6 +454,10 @@ func shouldStripDex(module ModuleConfig, global GlobalConfig) bool {
		strip = false
	}

	if module.NoStripping {
		strip = false
	}

	// Don't strip modules that are not on the system partition in case the oat/vdex version in system ROM
	// doesn't match the one in other partitions. It needs to be able to fall back to the APK for that case.
	if !strings.HasPrefix(module.DexLocation, SystemPartition) {
+54 −40
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ var testModuleConfig = ModuleConfig{
	NoCreateAppImage:       false,
	ForceCreateAppImage:    false,
	PresignedPrebuilt:      false,
	NoStripping:            false,
	StripInputPath:         "",
	StripOutputPath:        "",
}
@@ -162,6 +163,31 @@ func TestDexPreoptProfile(t *testing.T) {
}

func TestStripDex(t *testing.T) {
	tests := []struct {
		name  string
		setup func(global *GlobalConfig, module *ModuleConfig)
		strip bool
	}{
		{
			name:  "default strip",
			setup: func(global *GlobalConfig, module *ModuleConfig) {},
			strip: true,
		},
		{
			name:  "global no stripping",
			setup: func(global *GlobalConfig, module *ModuleConfig) { global.DefaultNoStripping = true },
			strip: false,
		},
		{
			name:  "module no stripping",
			setup: func(global *GlobalConfig, module *ModuleConfig) { module.NoStripping = true },
			strip: false,
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {

			global, module := testGlobalConfig, testModuleConfig

			module.Name = "test"
@@ -171,34 +197,19 @@ func TestStripDex(t *testing.T) {
			module.StripInputPath = "$1"
			module.StripOutputPath = "$2"

			test.setup(&global, &module)

			rule, err := GenerateStripRule(global, module)
			if err != nil {
				t.Error(err)
			}

			if test.strip {
				want := `zip2zip -i $1 -o $2 -x "classes*.dex"`
				if len(rule.Commands()) < 1 || !strings.Contains(rule.Commands()[0], want) {
					t.Errorf("\nwant commands[0] to have:\n   %v\ngot:\n   %v", want, rule.Commands()[0])
				}
}

func TestNoStripDex(t *testing.T) {
	global, module := testGlobalConfig, testModuleConfig

	global.DefaultNoStripping = true

	module.Name = "test"
	module.DexLocation = "/system/app/test/test.apk"
	module.BuildPath = "out/test/test.apk"
	module.Archs = []string{"arm"}
	module.StripInputPath = "$1"
	module.StripOutputPath = "$2"

	rule, err := GenerateStripRule(global, module)
	if err != nil {
		t.Error(err)
	}

			} else {
				wantCommands := []string{
					"cp -f $1 $2",
				}
@@ -206,3 +217,6 @@ func TestNoStripDex(t *testing.T) {
					t.Errorf("\nwant commands:\n   %v\ngot:\n   %v", wantCommands, rule.Commands())
				}
			}
		})
	}
}
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ type DexpreoptProperties struct {
		// true.
		Enabled *bool

		// If true, never strip the dex files from the final jar when dexpreopting.  Defaults to false.
		No_stripping *bool

		// If true, generate an app image (.art file) for this module.
		App_image *bool

@@ -171,6 +174,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
		NoCreateAppImage:    !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
		ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),

		NoStripping:     Bool(d.dexpreoptProperties.Dex_preopt.No_stripping),
		StripInputPath:  dexJarFile.String(),
		StripOutputPath: strippedDexJarFile.String(),
	}