Merge "Move fingerprint genrule and DCLA cc libraries to prod allowlists."
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 4d09a42..2917931 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -710,6 +710,10 @@
 		// for building com.android.neuralnetworks
 		"libimapper_stablec",
 		"libimapper_providerutils",
+
+		// min_sdk_version in android_app
+		"CtsShimUpgrade",
+		"fake-framework",
 	}
 
 	Bp2buildModuleTypeAlwaysConvertList = []string{
@@ -869,6 +873,9 @@
 		"android.hardware.health-translate-java",
 
 		// cc_test related.
+		// b/274164834 "Could not open Configuration file test.cfg"
+		"svcenc", "svcdec",
+
 		// Failing host cc_tests
 		"memunreachable_unit_test",
 		"libprocinfo_test",
diff --git a/android/androidmk.go b/android/androidmk.go
index a7b69f6..aa411d1 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -560,8 +560,6 @@
 		a.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", base.katiSymlinks.InstallPaths().Paths())
 	}
 
-	a.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", base.commonProperties.SkipInstall)
-
 	if am, ok := mod.(ApexModule); ok {
 		a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform())
 	}
diff --git a/android/apex.go b/android/apex.go
index a0ac5b8..358818f 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -603,7 +603,7 @@
 			// Do not install the module for platform, but still allow it to output
 			// uninstallable AndroidMk entries in certain cases when they have side
 			// effects.  TODO(jiyong): move this routine to somewhere else
-			mod.SkipInstall()
+			mod.MakeUninstallable()
 		}
 		if !platformVariation {
 			mctx.SetVariationProvider(mod, ApexInfoProvider, apexInfos[i-1])
diff --git a/android/module.go b/android/module.go
index b45ed95..773d77b 100644
--- a/android/module.go
+++ b/android/module.go
@@ -505,8 +505,8 @@
 	PartitionTag(DeviceConfig) string
 	HideFromMake()
 	IsHideFromMake() bool
-	SkipInstall()
 	IsSkipInstall() bool
+	MakeUninstallable()
 	ReplacedByPrebuilt()
 	IsReplacedByPrebuilt() bool
 	ExportedToMake() bool
@@ -1964,6 +1964,15 @@
 	return m.commonProperties.SkipInstall
 }
 
+// Similar to HideFromMake, but if the AndroidMk entry would set
+// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
+// rather than leaving it out altogether. That happens in cases where it would
+// have other side effects, in particular when it adds a NOTICE file target,
+// which other install targets might depend on.
+func (m *ModuleBase) MakeUninstallable() {
+	m.HideFromMake()
+}
+
 func (m *ModuleBase) ReplacedByPrebuilt() {
 	m.commonProperties.ReplacedByPrebuilt = true
 	m.HideFromMake()
diff --git a/android/packaging_test.go b/android/packaging_test.go
index f32d1c3..91ac1f3 100644
--- a/android/packaging_test.go
+++ b/android/packaging_test.go
@@ -15,7 +15,6 @@
 package android
 
 import (
-	"strings"
 	"testing"
 
 	"github.com/google/blueprint"
@@ -29,8 +28,6 @@
 		Deps         []string
 		Skip_install *bool
 	}
-
-	builtFile Path
 }
 
 // dep tag used in this test. All dependencies are considered as installable.
@@ -51,21 +48,13 @@
 }
 
 func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
-	m.builtFile = PathForModuleOut(ctx, m.Name())
+	builtFile := PathForModuleOut(ctx, m.Name())
 	dir := ctx.Target().Arch.ArchType.Multilib
 	installDir := PathForModuleInstall(ctx, dir)
 	if proptools.Bool(m.props.Skip_install) {
 		m.SkipInstall()
 	}
-	ctx.InstallFile(installDir, m.Name(), m.builtFile)
-}
-
-func (m *componentTestModule) AndroidMkEntries() []AndroidMkEntries {
-	return []AndroidMkEntries{
-		{
-			OutputFile: OptionalPathForPath(m.builtFile),
-		},
-	}
+	ctx.InstallFile(installDir, m.Name(), builtFile)
 }
 
 // Module that itself is a package
@@ -262,35 +251,6 @@
 		`, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
 }
 
-func TestSkipInstallProducesLocalUninstallableModule(t *testing.T) {
-	result := GroupFixturePreparers(
-		PrepareForTestWithArchMutator,
-		FixtureRegisterWithContext(func(ctx RegistrationContext) {
-			ctx.RegisterModuleType("component", componentTestModuleFactory)
-			ctx.RegisterModuleType("package_module", packageTestModuleFactory)
-		}),
-		FixtureWithRootAndroidBp(`
-component {
-	name: "foo",
-	skip_install: true,
-}
-
-package_module {
-	name: "package",
-	deps: ["foo"],
-}
-`),
-	).RunTest(t)
-	module := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*componentTestModule)
-	entries := AndroidMkEntriesForTest(t, result.TestContext, module)
-	builder := &strings.Builder{}
-	entries[0].write(builder)
-	androidMkString := builder.String()
-	if !strings.Contains(androidMkString, "LOCAL_UNINSTALLABLE_MODULE := true") {
-		t.Errorf("Expected android mk entries to contain \"LOCAL_UNINSTALLABLE_MODULE := true\", got: \n%s", androidMkString)
-	}
-}
-
 func TestPackagingBaseSingleTarget(t *testing.T) {
 	multiTarget := false
 	runPackagingTest(t, multiTarget,
diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go
index 03b3d2b..ef3f124 100644
--- a/bp2build/android_app_conversion_test.go
+++ b/bp2build/android_app_conversion_test.go
@@ -344,3 +344,50 @@
 			}),
 		}})
 }
+
+func TestAndroidAppMinSdkProvided(t *testing.T) {
+	runAndroidAppTestCase(t, Bp2buildTestCase{
+		Description:                "Android app with value for min_sdk_version",
+		ModuleTypeUnderTest:        "android_app",
+		ModuleTypeUnderTestFactory: java.AndroidAppFactory,
+		Filesystem:                 map[string]string{},
+		Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
+android_app {
+        name: "foo",
+        sdk_version: "current",
+				min_sdk_version: "24",
+}
+`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTarget("android_binary", "foo", AttrNameToString{
+				"manifest":       `"AndroidManifest.xml"`,
+				"resource_files": `[]`,
+				"manifest_values": `{
+        "minSdkVersion": "24",
+    }`,
+			}),
+		}})
+}
+
+func TestAndroidAppMinSdkDefaultToSdkVersion(t *testing.T) {
+	runAndroidAppTestCase(t, Bp2buildTestCase{
+		Description:                "Android app with value for sdk_version",
+		ModuleTypeUnderTest:        "android_app",
+		ModuleTypeUnderTestFactory: java.AndroidAppFactory,
+		Filesystem:                 map[string]string{},
+		Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
+android_app {
+        name: "foo",
+        sdk_version: "30",
+}
+`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTarget("android_binary", "foo", AttrNameToString{
+				"manifest":       `"AndroidManifest.xml"`,
+				"resource_files": `[]`,
+				"manifest_values": `{
+        "minSdkVersion": "30",
+    }`,
+			}),
+		}})
+}
diff --git a/cc/cc.go b/cc/cc.go
index 6e2a3dd..400814d 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -609,6 +609,7 @@
 	inSanitizerDir() bool
 	hostToolPath() android.OptionalPath
 	relativeInstallPath() string
+	makeUninstallable(mod *Module)
 	installInRoot() bool
 }
 
@@ -3524,6 +3525,14 @@
 	return c.InRecovery()
 }
 
+func (c *Module) MakeUninstallable() {
+	if c.installer == nil {
+		c.ModuleBase.MakeUninstallable()
+		return
+	}
+	c.installer.makeUninstallable(c)
+}
+
 func (c *Module) HostToolPath() android.OptionalPath {
 	if c.installer == nil {
 		return android.OptionalPath{}
diff --git a/cc/installer.go b/cc/installer.go
index c3618b7..e2c0e7b 100644
--- a/cc/installer.go
+++ b/cc/installer.go
@@ -121,6 +121,10 @@
 	return String(installer.Properties.Relative_install_path)
 }
 
+func (installer *baseInstaller) makeUninstallable(mod *Module) {
+	mod.ModuleBase.MakeUninstallable()
+}
+
 func (installer *baseInstaller) installInRoot() bool {
 	return Bool(installer.Properties.Install_in_root)
 }
diff --git a/cc/library.go b/cc/library.go
index 842a05f..68de233 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -2439,6 +2439,17 @@
 	return nil
 }
 
+func (library *libraryDecorator) makeUninstallable(mod *Module) {
+	if library.static() && library.buildStatic() && !library.buildStubs() {
+		// If we're asked to make a static library uninstallable we don't do
+		// anything since AndroidMkEntries always sets LOCAL_UNINSTALLABLE_MODULE
+		// for these entries. This is done to still get the make targets for NOTICE
+		// files from notice_files.mk, which other libraries might depend on.
+		return
+	}
+	mod.ModuleBase.MakeUninstallable()
+}
+
 func (library *libraryDecorator) getPartition() string {
 	return library.path.Partition()
 }
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index c237d75..5b7ba43 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -214,7 +214,7 @@
 			// without the prefix hack below.
 			if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() &&
 				!strings.HasPrefix(ctx.baseModuleName(), "libclang_rt.") {
-				ctx.Module().SkipInstall()
+				ctx.Module().MakeUninstallable()
 			}
 
 			return outputFile
diff --git a/java/androidmk.go b/java/androidmk.go
index d73ff46..a4dac80 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -76,6 +76,9 @@
 			entriesList = append(entriesList, dexpreoptEntries...)
 		}
 		entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
+	} else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
+		// Platform variant.  If not available for the platform, we don't need Make module.
+		entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
 	} else {
 		entriesList = append(entriesList, android.AndroidMkEntries{
 			Class:      "JAVA_LIBRARIES",
@@ -91,8 +94,7 @@
 						entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...)
 					}
 
-					if library.installFile == nil || !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
-						// If the ApexModule is not available for the platform, it shouldn't be installed.
+					if library.installFile == nil {
 						entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
 					}
 					if library.dexJarFile.IsSet() {
diff --git a/java/app.go b/java/app.go
index 4cc9e19..1a324bf 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1495,6 +1495,10 @@
 	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
 }
 
+type manifestValueAttribute struct {
+	MinSdkVersion *string
+}
+
 type bazelAndroidAppAttributes struct {
 	*javaCommonAttributes
 	*bazelAapt
@@ -1502,6 +1506,7 @@
 	Custom_package   *string
 	Certificate      bazel.LabelAttribute
 	Certificate_name bazel.StringAttribute
+	Manifest_values  *manifestValueAttribute
 }
 
 // ConvertWithBp2build is used to convert android_app to Bazel.
@@ -1516,11 +1521,22 @@
 
 	certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
 
+	manifestValues := &manifestValueAttribute{}
+	// MinSdkVersion(ctx) calls SdkVersion(ctx) if no value for min_sdk_version is set
+	minSdkSpec := a.MinSdkVersion(ctx)
+	if !minSdkSpec.ApiLevel.IsPreview() && minSdkSpec.Valid() {
+		minSdkStr, err := minSdkSpec.EffectiveVersionString(ctx)
+		if err == nil {
+			manifestValues.MinSdkVersion = &minSdkStr
+		}
+	}
+
 	appAttrs := &bazelAndroidAppAttributes{
 		// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
 		Custom_package:   a.overridableAppProperties.Package_name,
 		Certificate:      certificate,
 		Certificate_name: certificateName,
+		Manifest_values:  manifestValues,
 	}
 
 	props := bazel.BazelTargetModuleProperties{