Merge "Add par_test"
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index 8af08c1..a047e47 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -20,12 +20,12 @@
 	"strings"
 )
 
-// prebuilt_etc is for prebuilts that will be installed to
-// <partition>/etc/<subdir>
+// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
 
 func init() {
 	RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
 	RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
+	RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
 
 	PreDepsMutators(func(ctx RegisterMutatorsContext) {
 		ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
@@ -60,8 +60,10 @@
 
 	properties prebuiltEtcProperties
 
-	sourceFilePath         Path
-	outputFilePath         OutputPath
+	sourceFilePath Path
+	outputFilePath OutputPath
+	// The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
+	installDirBase         string
 	installDirPath         OutputPath
 	additionalDependencies *Paths
 }
@@ -124,7 +126,7 @@
 		return
 	}
 	p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
-	p.installDirPath = PathForModuleInstall(ctx, "etc", String(p.properties.Sub_dir))
+	p.installDirPath = PathForModuleInstall(ctx, p.installDirBase, String(p.properties.Sub_dir))
 
 	// This ensures that outputFilePath has the correct name for others to
 	// use, as the source file may have a different name.
@@ -174,8 +176,9 @@
 	p.AddProperties(&p.properties)
 }
 
+// prebuilt_etc is for prebuilts that will be installed to <partition>/etc/<subdir>
 func PrebuiltEtcFactory() Module {
-	module := &PrebuiltEtc{}
+	module := &PrebuiltEtc{installDirBase: "etc"}
 	InitPrebuiltEtcModule(module)
 	// This module is device-only
 	InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
@@ -183,13 +186,22 @@
 }
 
 func PrebuiltEtcHostFactory() Module {
-	module := &PrebuiltEtc{}
+	module := &PrebuiltEtc{installDirBase: "etc"}
 	InitPrebuiltEtcModule(module)
 	// This module is host-only
 	InitAndroidArchModule(module, HostSupported, MultilibCommon)
 	return module
 }
 
+// prebuilt_usr_share is for prebuilts that will be installed to <partition>/usr/share/<subdir>
+func PrebuiltUserShareFactory() Module {
+	module := &PrebuiltEtc{installDirBase: "usr/share"}
+	InitPrebuiltEtcModule(module)
+	// This module is device-only
+	InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
+	return module
+}
+
 const (
 	// coreMode is the variant for modules to be installed to system.
 	coreMode = "core"
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
index d0961a7..206f53b 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -29,6 +29,7 @@
 	ctx := NewTestArchContext()
 	ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory))
 	ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory))
+	ctx.RegisterModuleType("prebuilt_usr_share", ModuleFactoryAdaptor(PrebuiltUserShareFactory))
 	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
 		ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
 	})
@@ -193,3 +194,19 @@
 		t.Errorf("host bit is not set for a prebuilt_etc_host module.")
 	}
 }
+
+func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
+	ctx := testPrebuiltEtc(t, `
+		prebuilt_usr_share {
+			name: "foo.conf",
+			src: "foo.conf",
+			sub_dir: "bar",
+		}
+	`)
+
+	p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
+	expected := "target/product/test_device/system/usr/share/bar"
+	if p.installDirPath.RelPathString() != expected {
+		t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
+	}
+}
diff --git a/apex/apex.go b/apex/apex.go
index 5e1a943..7633ad2 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -257,18 +257,8 @@
 
 	Multilib apexMultilibProperties
 
-	Prefer_sanitize struct {
-		// Prefer native libraries with asan if available
-		Address *bool
-		// Prefer native libraries with hwasan if available
-		Hwaddress *bool
-		// Prefer native libraries with tsan if available
-		Thread *bool
-		// Prefer native libraries with integer_overflow if available
-		Integer_overflow *bool
-		// Prefer native libraries with cfi if available
-		Cfi *bool
-	}
+	// List of sanitizer names that this APEX is enabled for
+	SanitizerNames []string `blueprint:"mutated"`
 }
 
 type apexTargetBundleProperties struct {
@@ -551,29 +541,15 @@
 	}
 }
 
+func (a *apexBundle) EnableSanitizer(sanitizerName string) {
+	if !android.InList(sanitizerName, a.properties.SanitizerNames) {
+		a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
+	}
+}
+
 func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
-	// If this APEX is configured to prefer a sanitizer, use it
-	switch sanitizerName {
-	case "asan":
-		if proptools.Bool(a.properties.Prefer_sanitize.Address) {
-			return true
-		}
-	case "hwasan":
-		if proptools.Bool(a.properties.Prefer_sanitize.Hwaddress) {
-			return true
-		}
-	case "tsan":
-		if proptools.Bool(a.properties.Prefer_sanitize.Thread) {
-			return true
-		}
-	case "cfi":
-		if proptools.Bool(a.properties.Prefer_sanitize.Cfi) {
-			return true
-		}
-	case "integer_overflow":
-		if proptools.Bool(a.properties.Prefer_sanitize.Integer_overflow) {
-			return true
-		}
+	if android.InList(sanitizerName, a.properties.SanitizerNames) {
+		return true
 	}
 
 	// Then follow the global setting
diff --git a/cc/sanitize.go b/cc/sanitize.go
index fc2ed50..7297718 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -666,6 +666,14 @@
 				}
 				return true
 			})
+		} else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok {
+			// If an APEX module includes a lib which is enabled for a sanitizer T, then
+			// the APEX module is also enabled for the same sanitizer type.
+			mctx.VisitDirectDeps(func(child android.Module) {
+				if c, ok := child.(*Module); ok && c.sanitize.isSanitizerEnabled(t) {
+					sanitizeable.EnableSanitizer(t.name())
+				}
+			})
 		}
 	}
 }
@@ -848,6 +856,7 @@
 type Sanitizeable interface {
 	android.Module
 	IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool
+	EnableSanitizer(sanitizerName string)
 }
 
 // Create sanitized variants for modules that need them
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 1a70d49..85e4797 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -171,12 +171,11 @@
 	// list of java libraries that will be in the classpath.
 	Libs []string `android:"arch_variant"`
 
-	// don't build against the default libraries (bootclasspath, legacy-test, core-junit,
-	// ext, and framework for device targets)
+	// don't build against the default libraries (bootclasspath, ext, and framework for device
+	// targets)
 	No_standard_libs *bool
 
-	// don't build against the framework libraries (legacy-test, core-junit,
-	// ext, and framework for device targets)
+	// don't build against the framework libraries (ext, and framework for device targets)
 	No_framework_libs *bool
 
 	// the java library (in classpath) for documentation that provides java srcs and srcjars.
diff --git a/java/java.go b/java/java.go
index c0310da..880f920 100644
--- a/java/java.go
+++ b/java/java.go
@@ -78,12 +78,11 @@
 	// list of files that should be excluded from java_resources and java_resource_dirs
 	Exclude_java_resources []string `android:"arch_variant"`
 
-	// don't build against the default libraries (bootclasspath, legacy-test, core-junit,
-	// ext, and framework for device targets)
+	// don't build against the default libraries (bootclasspath, ext, and framework for device
+	// targets)
 	No_standard_libs *bool
 
-	// don't build against the framework libraries (legacy-test, core-junit,
-	// ext, and framework for device targets)
+	// don't build against the framework libraries (ext, and framework for device targets)
 	No_framework_libs *bool
 
 	// list of module-specific flags that will be used for javac compiles