Merge "Replace ndk_libs.bzl with an attr in cc_stub_suite" into main
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 1e7bc5e..16e2328 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -324,31 +324,35 @@
 
 		"libnativehelper": Bp2BuildDefaultTrueRecursively,
 
-		"packages/apps/DevCamera":                                    Bp2BuildDefaultTrue,
-		"packages/apps/HTMLViewer":                                   Bp2BuildDefaultTrue,
-		"packages/apps/Protips":                                      Bp2BuildDefaultTrue,
-		"packages/apps/SafetyRegulatoryInfo":                         Bp2BuildDefaultTrue,
-		"packages/apps/WallpaperPicker":                              Bp2BuildDefaultTrue,
-		"packages/modules/NeuralNetworks/driver/cache":               Bp2BuildDefaultTrueRecursively,
-		"packages/modules/StatsD/lib/libstatssocket":                 Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb":                                       Bp2BuildDefaultTrue,
-		"packages/modules/adb/apex":                                  Bp2BuildDefaultTrue,
-		"packages/modules/adb/fastdeploy":                            Bp2BuildDefaultTrue,
-		"packages/modules/adb/crypto":                                Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb/libs":                                  Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb/pairing_auth":                          Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb/pairing_connection":                    Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb/proto":                                 Bp2BuildDefaultTrueRecursively,
-		"packages/modules/adb/tls":                                   Bp2BuildDefaultTrueRecursively,
-		"packages/modules/Connectivity/staticlibs/native":            Bp2BuildDefaultTrueRecursively,
-		"packages/modules/Connectivity/staticlibs/netd/libnetdutils": Bp2BuildDefaultTrueRecursively,
-		"packages/modules/Gki/libkver":                               Bp2BuildDefaultTrue,
-		"packages/modules/NetworkStack/common/captiveportal":         Bp2BuildDefaultTrue,
-		"packages/modules/NeuralNetworks/apex":                       Bp2BuildDefaultTrue,
-		"packages/modules/NeuralNetworks/apex/testing":               Bp2BuildDefaultTrue,
-		"packages/providers/MediaProvider/tools/dialogs":             Bp2BuildDefaultFalse, // TODO(b/242834374)
-		"packages/screensavers/Basic":                                Bp2BuildDefaultTrue,
-		"packages/services/Car/tests/SampleRearViewCamera":           Bp2BuildDefaultFalse, // TODO(b/242834321)
+		"packages/apps/DevCamera":                            Bp2BuildDefaultTrue,
+		"packages/apps/HTMLViewer":                           Bp2BuildDefaultTrue,
+		"packages/apps/Protips":                              Bp2BuildDefaultTrue,
+		"packages/apps/SafetyRegulatoryInfo":                 Bp2BuildDefaultTrue,
+		"packages/apps/WallpaperPicker":                      Bp2BuildDefaultTrue,
+		"packages/modules/NeuralNetworks/driver/cache":       Bp2BuildDefaultTrueRecursively,
+		"packages/modules/StatsD/lib/libstatssocket":         Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb":                               Bp2BuildDefaultTrue,
+		"packages/modules/adb/apex":                          Bp2BuildDefaultTrue,
+		"packages/modules/adb/fastdeploy":                    Bp2BuildDefaultTrue,
+		"packages/modules/adb/crypto":                        Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb/libs":                          Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb/pairing_auth":                  Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb/pairing_connection":            Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb/proto":                         Bp2BuildDefaultTrueRecursively,
+		"packages/modules/adb/tls":                           Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/bpf_progs":            Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/service-t":            Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/service/native":       Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/staticlibs/native":    Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/staticlibs/netd":      Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Connectivity/tests/unit/jni":       Bp2BuildDefaultTrueRecursively,
+		"packages/modules/Gki/libkver":                       Bp2BuildDefaultTrue,
+		"packages/modules/NetworkStack/common/captiveportal": Bp2BuildDefaultTrue,
+		"packages/modules/NeuralNetworks/apex":               Bp2BuildDefaultTrue,
+		"packages/modules/NeuralNetworks/apex/testing":       Bp2BuildDefaultTrue,
+		"packages/providers/MediaProvider/tools/dialogs":     Bp2BuildDefaultFalse, // TODO(b/242834374)
+		"packages/screensavers/Basic":                        Bp2BuildDefaultTrue,
+		"packages/services/Car/tests/SampleRearViewCamera":   Bp2BuildDefaultFalse, // TODO(b/242834321)
 
 		"platform_testing/libraries/annotations":              Bp2BuildDefaultTrueRecursively,
 		"platform_testing/libraries/flag-helpers/libflagtest": Bp2BuildDefaultTrueRecursively,
@@ -997,6 +1001,9 @@
 		"tradefed-device-build-interfaces",
 		"tradefed-invocation-interfaces",
 		"tradefed-lib-core",
+
+		"libandroid_net_connectivity_com_android_net_module_util_jni",
+		"libservice-connectivity",
 	}
 
 	Bp2buildModuleTypeAlwaysConvertList = []string{
diff --git a/android/config.go b/android/config.go
index a7a96b7..04b43ac 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1011,12 +1011,18 @@
 
 func (c *config) PreviewApiLevels() []ApiLevel {
 	var levels []ApiLevel
-	for i, codename := range c.PlatformVersionActiveCodenames() {
+	i := 0
+	for _, codename := range c.PlatformVersionActiveCodenames() {
+		if codename == "REL" {
+			continue
+		}
+
 		levels = append(levels, ApiLevel{
 			value:     codename,
 			number:    i,
 			isPreview: true,
 		})
+		i++
 	}
 	return levels
 }
diff --git a/cc/lto.go b/cc/lto.go
index 281b527..d48be14 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -68,7 +68,7 @@
 
 func (lto *lto) begin(ctx BaseModuleContext) {
 	// First, determine the module independent default LTO mode.
-	ltoDefault := GlobalThinLTO(ctx)
+	ltoDefault := true
 	if ctx.Config().IsEnvTrue("DISABLE_LTO") {
 		ltoDefault = false
 	} else if lto.Never() {
@@ -163,10 +163,6 @@
 	return lto != nil && proptools.Bool(lto.Properties.Lto.Never)
 }
 
-func GlobalThinLTO(ctx android.BaseModuleContext) bool {
-	return !ctx.Config().IsEnvFalse("GLOBAL_THINLTO")
-}
-
 // Propagate lto requirements down from binaries
 func ltoDepsMutator(mctx android.TopDownMutatorContext) {
 	if m, ok := mctx.Module().(*Module); ok {
@@ -205,8 +201,6 @@
 
 // Create lto variants for modules that need them
 func ltoMutator(mctx android.BottomUpMutatorContext) {
-	globalThinLTO := GlobalThinLTO(mctx)
-
 	if m, ok := mctx.Module().(*Module); ok && m.lto != nil {
 		// Create variations for LTO types required as static
 		// dependencies
@@ -218,10 +212,10 @@
 			variationNames = append(variationNames, "lto-none")
 		}
 
-		if globalThinLTO && !m.lto.Properties.LtoEnabled {
+		if !m.lto.Properties.LtoEnabled {
 			mctx.SetDependencyVariation("lto-none")
 		}
-		if !globalThinLTO && m.lto.Properties.LtoEnabled {
+		if m.lto.Properties.LtoEnabled {
 			mctx.SetDependencyVariation("lto-thin")
 		}
 
diff --git a/genrule/allowlists.go b/genrule/allowlists.go
index 3e92706..9647a18 100644
--- a/genrule/allowlists.go
+++ b/genrule/allowlists.go
@@ -17,6 +17,7 @@
 var (
 	DepfileAllowList = []string{
 		"depfile_allowed_for_test",
+		"tflite_support_metadata_schema",
 		"tflite_support_spm_config",
 		"tflite_support_spm_encoder_config",
 		"gen_uwb_core_proto",
@@ -249,6 +250,13 @@
 		"ue_unittest_erofs_imgs",
 		"vts_vndk_abi_dump_zip",
 		"atest_integration_fake_src",
+		"VehicleServerProtoStub_cc@2.0-grpc-trout",
+		"VehicleServerProtoStub_cc@default-grpc",
+		"VehicleServerProtoStub_h@default-grpc",
+		"VehicleServerProtoStub_h@2.0-grpc-trout",
+		"chre_atoms_log.h",
+		"checkIn-service-stub-lite",
+		"seller-frontend-service-stub-lite",
 	}
 
 	SandboxingDenyPathList = []string{
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index 3a6854c..78ab771 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -635,6 +635,13 @@
 	case "+=":
 		asgn.flavor = asgnAppend
 	case "?=":
+		if _, ok := lhs.(*productConfigVariable); ok {
+			// Make sets all product configuration variables to empty strings before running product
+			// config makefiles. ?= will have no effect on a variable that has been assigned before,
+			// even if assigned to an empty string. So just skip emitting any code for this
+			// assignment.
+			return nil
+		}
 		asgn.flavor = asgnMaybeSet
 	default:
 		panic(fmt.Errorf("unexpected assignment type %s", a.Type))
diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go
index a9b6197..0c4d213 100644
--- a/mk2rbc/mk2rbc_test.go
+++ b/mk2rbc/mk2rbc_test.go
@@ -923,8 +923,6 @@
   cfg["PRODUCT_LIST2"] += ["a"]
   cfg["PRODUCT_LIST1"] += ["b"]
   cfg["PRODUCT_LIST2"] += ["b"]
-  if cfg.get("PRODUCT_LIST3") == None:
-    cfg["PRODUCT_LIST3"] = ["a"]
   cfg["PRODUCT_LIST1"] = ["c"]
   g.setdefault("PLATFORM_LIST", [])
   g["PLATFORM_LIST"] += ["x"]
@@ -966,9 +964,10 @@
 PRODUCT_LIST2 ?= a $(PRODUCT_LIST2)
 PRODUCT_LIST3 += a
 
-# Now doing them again should not have a setdefault because they've already been set
+# Now doing them again should not have a setdefault because they've already been set, except 2
+# which did not emit an assignment before
 PRODUCT_LIST1 = a $(PRODUCT_LIST1)
-PRODUCT_LIST2 ?= a $(PRODUCT_LIST2)
+PRODUCT_LIST2 = a $(PRODUCT_LIST2)
 PRODUCT_LIST3 += a
 `,
 		expected: `# All of these should have a setdefault because they're self-referential and not defined before
@@ -979,18 +978,15 @@
   rblf.setdefault(handle, "PRODUCT_LIST1")
   cfg["PRODUCT_LIST1"] = (["a"] +
       cfg.get("PRODUCT_LIST1", []))
-  if cfg.get("PRODUCT_LIST2") == None:
-    rblf.setdefault(handle, "PRODUCT_LIST2")
-    cfg["PRODUCT_LIST2"] = (["a"] +
-        cfg.get("PRODUCT_LIST2", []))
   rblf.setdefault(handle, "PRODUCT_LIST3")
   cfg["PRODUCT_LIST3"] += ["a"]
-  # Now doing them again should not have a setdefault because they've already been set
+  # Now doing them again should not have a setdefault because they've already been set, except 2
+  # which did not emit an assignment before
   cfg["PRODUCT_LIST1"] = (["a"] +
       cfg["PRODUCT_LIST1"])
-  if cfg.get("PRODUCT_LIST2") == None:
-    cfg["PRODUCT_LIST2"] = (["a"] +
-        cfg["PRODUCT_LIST2"])
+  rblf.setdefault(handle, "PRODUCT_LIST2")
+  cfg["PRODUCT_LIST2"] = (["a"] +
+      cfg.get("PRODUCT_LIST2", []))
   cfg["PRODUCT_LIST3"] += ["a"]
 `,
 	},
diff --git a/mk2rbc/variable.go b/mk2rbc/variable.go
index 0a26ed8..95e1f8e 100644
--- a/mk2rbc/variable.go
+++ b/mk2rbc/variable.go
@@ -109,14 +109,11 @@
 		}
 		emitAppend()
 	case asgnMaybeSet:
-		gctx.writef("if cfg.get(%q) == None:", pcv.nam)
-		gctx.indentLevel++
-		gctx.newLine()
-		if needsSetDefault {
-			emitSetDefault()
-		}
-		emitAssignment()
-		gctx.indentLevel--
+		// In mk2rbc.go we never emit a maybeSet assignment for product config variables, because
+		// they are set to empty strings before running product config.
+		panic("Should never get here")
+	default:
+		panic("Unknown assignment flavor")
 	}
 
 	gctx.setHasBeenAssigned(&pcv)