Merge "APEXes can be sanitized"
diff --git a/OWNERS b/OWNERS
index d56644b..892beb7 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,4 +1,4 @@
-per-file * = ccross@android.com,dwillemsen@google.com,nanzhang@google.com,jungjw@google.com
+per-file * = ccross@android.com,dwillemsen@google.com,jungjw@google.com
 per-file ndk_*.go, *gen_stub_libs.py = danalbert@google.com
 per-file clang.go,global.go = srhines@google.com, chh@google.com, pirama@google.com, yikong@google.com
 per-file tidy.go = srhines@google.com, chh@google.com
diff --git a/android/arch.go b/android/arch.go
index bee09b0..e8d9c6e 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -106,6 +106,7 @@
 var archVariants = map[ArchType][]string{}
 var archFeatures = map[ArchType][]string{}
 var archFeatureMap = map[ArchType]map[string][]string{}
+var defaultArchFeatureMap = map[OsType]map[ArchType][]string{}
 
 func RegisterArchVariants(arch ArchType, variants ...string) {
 	checkCalledFromInit()
@@ -117,9 +118,24 @@
 	archFeatures[arch] = append(archFeatures[arch], features...)
 }
 
+func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) {
+	checkCalledFromInit()
+
+	for _, feature := range features {
+		if !InList(feature, archFeatures[arch]) {
+			panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch))
+		}
+	}
+
+	if defaultArchFeatureMap[os] == nil {
+		defaultArchFeatureMap[os] = make(map[ArchType][]string)
+	}
+	defaultArchFeatureMap[os][arch] = features
+}
+
 func RegisterArchVariantFeatures(arch ArchType, variant string, features ...string) {
 	checkCalledFromInit()
-	if variant != "" && !InList(variant, archVariants[arch]) {
+	if !InList(variant, archVariants[arch]) {
 		panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch))
 	}
 
@@ -952,7 +968,7 @@
 			return
 		}
 
-		arch, err := decodeArch(archName, archVariant, cpuVariant, abi)
+		arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi)
 		if err != nil {
 			targetErr = err
 			return
@@ -1127,11 +1143,11 @@
 	}
 }
 
-func decodeArchSettings(archConfigs []archConfig) ([]Target, error) {
+func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) {
 	var ret []Target
 
 	for _, config := range archConfigs {
-		arch, err := decodeArch(config.arch, &config.archVariant,
+		arch, err := decodeArch(os, config.arch, &config.archVariant,
 			&config.cpuVariant, &config.abi)
 		if err != nil {
 			return nil, err
@@ -1147,7 +1163,7 @@
 }
 
 // Convert a set of strings from product variables into a single Arch struct
-func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) {
+func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) {
 	stringPtr := func(p *string) string {
 		if p != nil {
 			return *p
@@ -1190,8 +1206,14 @@
 		}
 	}
 
-	if featureMap, ok := archFeatureMap[archType]; ok {
-		a.ArchFeatures = featureMap[a.ArchVariant]
+	if a.ArchVariant == "" {
+		if featureMap, ok := defaultArchFeatureMap[os]; ok {
+			a.ArchFeatures = featureMap[archType]
+		}
+	} else {
+		if featureMap, ok := archFeatureMap[archType]; ok {
+			a.ArchFeatures = featureMap[a.ArchVariant]
+		}
 	}
 
 	return a, nil
diff --git a/android/config.go b/android/config.go
index 38f6ec8..925ca94 100644
--- a/android/config.go
+++ b/android/config.go
@@ -303,7 +303,7 @@
 	}
 
 	if archConfig != nil {
-		androidTargets, err := decodeArchSettings(archConfig)
+		androidTargets, err := decodeArchSettings(Android, archConfig)
 		if err != nil {
 			return Config{}, err
 		}
@@ -749,6 +749,14 @@
 	return c.productVariables.ModulesLoadedByPrivilegedModules
 }
 
+func (c *config) BootJars() []string {
+	return c.productVariables.BootJars
+}
+
+func (c *config) PreoptBootJars() []string {
+	return c.productVariables.PreoptBootJars
+}
+
 func (c *config) DisableDexPreopt(name string) bool {
 	return Bool(c.productVariables.DisableDexPreopt) || InList(name, c.productVariables.DisableDexPreoptModules)
 }
diff --git a/android/variable.go b/android/variable.go
index 7e976cd..ddaf166 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -198,6 +198,9 @@
 	UncompressPrivAppDex             *bool    `json:",omitempty"`
 	ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
 
+	BootJars       []string `json:",omitempty"`
+	PreoptBootJars []string `json:",omitempty"`
+
 	DisableDexPreopt        *bool    `json:",omitempty"`
 	DisableDexPreoptModules []string `json:",omitempty"`
 	DexPreoptProfileDir     *string  `json:",omitempty"`
diff --git a/cc/config/clang.go b/cc/config/clang.go
index a0ebd10..832689b 100644
--- a/cc/config/clang.go
+++ b/cc/config/clang.go
@@ -135,10 +135,6 @@
 		// codebase for it.
 		"-Wno-inconsistent-missing-override",
 
-		// Bug: http://b/29823425 Disable -Wnull-dereference until the
-		// new instances detected by this warning are fixed.
-		"-Wno-null-dereference",
-
 		// Enable clang's thread-safety annotations in libcxx.
 		// Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything.
 		"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
@@ -187,6 +183,10 @@
 		// http://b/72331524 Allow null pointer arithmetic until the instances detected by
 		// this new warning are fixed.
 		"-Wno-null-pointer-arithmetic",
+
+		// Bug: http://b/29823425 Disable -Wnull-dereference until the
+		// new instances detected by this warning are fixed.
+		"-Wno-null-dereference",
 	}, " "))
 }
 
diff --git a/cc/config/global.go b/cc/config/global.go
index 13ad27c..5d98d67 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -120,8 +120,8 @@
 
 	// prebuilts/clang default settings.
 	ClangDefaultBase         = "prebuilts/clang/host"
-	ClangDefaultVersion      = "clang-r346389b"
-	ClangDefaultShortVersion = "8.0.6"
+	ClangDefaultVersion      = "clang-r346389c"
+	ClangDefaultShortVersion = "8.0.7"
 
 	// Directories with warnings from Android.bp files.
 	WarningAllowedProjects = []string{
diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go
index ff8a6da..381f7e7 100644
--- a/cc/config/x86_64_device.go
+++ b/cc/config/x86_64_device.go
@@ -81,7 +81,7 @@
 		"aes_ni",
 		"avx",
 		"popcnt")
-	android.RegisterArchVariantFeatures(android.X86_64, "",
+	android.RegisterDefaultArchVariantFeatures(android.Android, android.X86_64,
 		"ssse3",
 		"sse4",
 		"sse4_1",
diff --git a/cc/library.go b/cc/library.go
index da223dc..4adb081 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -646,6 +646,11 @@
 			linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
 		}
 	}
+	if library.buildStubs() {
+		linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String()
+		flags.LdFlags = append(flags.LdFlags, linkerScriptFlags)
+		linkerDeps = append(linkerDeps, library.versionScriptPath)
+	}
 
 	fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
 	outputFile := android.PathForModuleOut(ctx, fileName)
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 6b5c40d..503af7e 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -36,6 +36,7 @@
 	PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
 
 	BootJars         []string // modules for jars that form the boot class path
+	PreoptBootJars   []string // modules for jars that form the boot image
 	SystemServerJars []string // jars that form the system server
 	SystemServerApps []string // apps that are loaded into system server
 	SpeedApps        []string // apps that should be speed optimized
diff --git a/java/java.go b/java/java.go
index fa4aee4..a23835b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1364,6 +1364,12 @@
 }
 
 func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
+	// Store uncompressed (and do not strip) dex files from boot class path jars that are not
+	// part of the boot image.
+	if inList(ctx.ModuleName(), ctx.Config().BootJars()) &&
+		!inList(ctx.ModuleName(), ctx.Config().PreoptBootJars()) {
+		return true
+	}
 	return false
 }
 
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 55a9590..941e665 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -134,11 +134,6 @@
 	// Defaults to "android.annotation".
 	Srcs_lib_whitelist_pkgs []string
 
-	// if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
-	// currently still used for documentation generation, and will be replaced by Dokka soon.
-	// Defaults to true.
-	Metalava_enabled *bool
-
 	// TODO: determines whether to create HTML doc or not
 	//Html_doc *bool
 }
@@ -447,9 +442,6 @@
 			Local_include_dirs []string
 		}
 	}{}
-	droiddocProps := struct {
-		Custom_template *string
-	}{}
 
 	props.Name = proptools.StringPtr(module.docsName(apiScope))
 	props.Srcs = append(props.Srcs, module.properties.Srcs...)
@@ -462,25 +454,12 @@
 	props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs
 	props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs
 
-	if module.properties.Metalava_enabled == nil {
-		module.properties.Metalava_enabled = proptools.BoolPtr(true)
-	}
-
-	droiddocArgs := ""
-	if Bool(module.properties.Metalava_enabled) == true {
-		droiddocArgs = " --stub-packages " + strings.Join(module.properties.Api_packages, ":") +
-			" " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " --hide-package ") +
-			" " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") +
-			" --hide MissingPermission --hide BroadcastBehavior " +
-			"--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
-			"--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
-	} else {
-		droiddocProps.Custom_template = proptools.StringPtr("droiddoc-templates-sdk")
-		droiddocArgs = " -stubpackages " + strings.Join(module.properties.Api_packages, ":") +
-			" " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " -hidePackage ") +
-			" " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") +
-			" -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128 -nodocs"
-	}
+	droiddocArgs := " --stub-packages " + strings.Join(module.properties.Api_packages, ":") +
+		" " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " --hide-package ") +
+		" " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") +
+		" --hide MissingPermission --hide BroadcastBehavior " +
+		"--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
+		"--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
 
 	switch apiScope {
 	case apiScopeSystem:
@@ -519,45 +498,11 @@
 		module.latestApiFilegroupName(apiScope))
 	props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
 		module.latestRemovedApiFilegroupName(apiScope))
-	if Bool(module.properties.Metalava_enabled) == false {
-		// any change is reported as error
-		props.Check_api.Current.Args = proptools.StringPtr("-error 2 -error 3 -error 4 -error 5 " +
-			"-error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 " +
-			"-error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " +
-			"-error 21 -error 23 -error 24 -error 25 -error 26 -error 27")
+	props.Srcs_lib = module.properties.Srcs_lib
+	props.Srcs_lib_whitelist_dirs = module.properties.Srcs_lib_whitelist_dirs
+	props.Srcs_lib_whitelist_pkgs = module.properties.Srcs_lib_whitelist_pkgs
 
-		// backward incompatible changes are reported as error
-		props.Check_api.Last_released.Args = proptools.StringPtr("-hide 2 -hide 3 -hide 4 -hide 5 " +
-			"-hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " +
-			"-error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 " +
-			"-error 15 -error 16 -error 17 -error 18")
-
-		// Include the part of the framework source. This is required for the case when
-		// API class is extending from the framework class. In that case, doclava needs
-		// to know whether the base class is hidden or not. Since that information is
-		// encoded as @hide string in the comment, we need source files for the classes,
-		// not the compiled ones.
-		props.Srcs_lib = proptools.StringPtr("framework")
-		props.Srcs_lib_whitelist_dirs = []string{"core/java"}
-
-		// Add android.annotation package to give access to the framework-defined
-		// annotations such as SystemApi, NonNull, etc.
-		if module.properties.Srcs_lib_whitelist_pkgs != nil {
-			props.Srcs_lib_whitelist_pkgs = module.properties.Srcs_lib_whitelist_pkgs
-		} else {
-			props.Srcs_lib_whitelist_pkgs = []string{"android.annotation"}
-		}
-	} else {
-		props.Srcs_lib = module.properties.Srcs_lib
-		props.Srcs_lib_whitelist_dirs = module.properties.Srcs_lib_whitelist_dirs
-		props.Srcs_lib_whitelist_pkgs = module.properties.Srcs_lib_whitelist_pkgs
-	}
-
-	if Bool(module.properties.Metalava_enabled) == true {
-		mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
-	} else {
-		mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props, &droiddocProps)
-	}
+	mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
 }
 
 // Creates the runtime library. This is not directly linkable from other modules.
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 4dc62b8..f4ef034 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -85,7 +85,6 @@
 	"egrep":     Allowed,
 	"find":      Allowed,
 	"fuser":     Allowed,
-	"getconf":   Allowed,
 	"getopt":    Allowed,
 	"git":       Allowed,
 	"grep":      Allowed,
@@ -98,7 +97,6 @@
 	"lsof":      Allowed,
 	"m4":        Allowed,
 	"md5sum":    Allowed,
-	"mktemp":    Allowed,
 	"mv":        Allowed,
 	"openssl":   Allowed,
 	"patch":     Allowed,
@@ -109,7 +107,6 @@
 	"python":    Allowed,
 	"python2.7": Allowed,
 	"python3":   Allowed,
-	"readlink":  Allowed,
 	"realpath":  Allowed,
 	"rm":        Allowed,
 	"rsync":     Allowed,
@@ -118,15 +115,12 @@
 	"sha1sum":   Allowed,
 	"sha256sum": Allowed,
 	"sha512sum": Allowed,
-	"sort":      Allowed,
-	"stat":      Allowed,
 	"tar":       Allowed,
 	"timeout":   Allowed,
 	"tr":        Allowed,
 	"unzip":     Allowed,
 	"wc":        Allowed,
 	"which":     Allowed,
-	"xargs":     Allowed,
 	"xz":        Allowed,
 	"zip":       Allowed,
 	"zipinfo":   Allowed,
@@ -158,16 +152,21 @@
 	"env":      Toybox,
 	"expr":     Toybox,
 	"head":     Toybox,
+	"getconf":  Toybox,
 	"id":       Toybox,
 	"ln":       Toybox,
 	"ls":       Toybox,
 	"mkdir":    Toybox,
+	"mktemp":   Toybox,
 	"od":       Toybox,
 	"paste":    Toybox,
 	"pwd":      Toybox,
+	"readlink": Toybox,
 	"rmdir":    Toybox,
 	"setsid":   Toybox,
 	"sleep":    Toybox,
+	"sort":     Toybox,
+	"stat":     Toybox,
 	"tail":     Toybox,
 	"tee":      Toybox,
 	"touch":    Toybox,
@@ -176,6 +175,7 @@
 	"uniq":     Toybox,
 	"unix2dos": Toybox,
 	"whoami":   Toybox,
+	"xargs":    Toybox,
 	"xxd":      Toybox,
 }