Merge "Set apex_available property" into rvc-dev
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 0e1bfc6..f984966 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -47,6 +47,8 @@
 const SystemPartition = "/system/"
 const SystemOtherPartition = "/system_other/"
 
+var DexpreoptRunningInSoong = false
+
 // GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
 // ModuleConfig.  The produced files and their install locations will be available through rule.Installs().
 func GenerateDexpreoptRule(ctx android.PathContext, globalSoong *GlobalSoongConfig,
@@ -589,7 +591,14 @@
 // at that time (Soong processes the jars in dependency order, which may be different from the
 // the system server classpath order).
 func SystemServerDexJarHostPath(ctx android.PathContext, jar string) android.OutputPath {
-	return android.PathForOutput(ctx, "system_server_dexjars", jar+".jar")
+	if DexpreoptRunningInSoong {
+		// Soong module, just use the default output directory $OUT/soong.
+		return android.PathForOutput(ctx, "system_server_dexjars", jar+".jar")
+	} else {
+		// Make module, default output directory is $OUT (passed via the "null config" created
+		// by dexpreopt_gen). Append Soong subdirectory to match Soong module paths.
+		return android.PathForOutput(ctx, "soong", "system_server_dexjars", jar+".jar")
+	}
 }
 
 func contains(l []string, s string) bool {
diff --git a/java/app.go b/java/app.go
index 0ec2502..f812335 100755
--- a/java/app.go
+++ b/java/app.go
@@ -112,7 +112,9 @@
 	IsCoverageVariant bool `blueprint:"mutated"`
 
 	// Whether this app is considered mainline updatable or not. When set to true, this will enforce
-	// additional rules for making sure that the APK is truly updatable. Default is false.
+	// additional rules to make sure an app can safely be updated. Default is false.
+	// Prefer using other specific properties if build behaviour must be changed; avoid using this
+	// flag for anything but neverallow rules (unless the behaviour change is invisible to owners).
 	Updatable *bool
 }
 
@@ -255,6 +257,9 @@
 		if !a.sdkVersion().stable() {
 			ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
 		}
+		if String(a.deviceProperties.Min_sdk_version) == "" {
+			ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
+		}
 	}
 
 	a.checkPlatformAPI(ctx)
diff --git a/java/app_test.go b/java/app_test.go
index 39460dc..55c1d76 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -276,6 +276,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "29",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -285,6 +286,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "system_29",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -294,6 +296,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "current",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -303,6 +306,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "system_current",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -312,6 +316,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "module_current",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -321,6 +326,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "core_current",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 		},
@@ -330,6 +336,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					platform_apis: true,
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 			expectedError: "Updatable apps must use stable SDKs",
@@ -340,6 +347,7 @@
 					name: "foo",
 					srcs: ["a.java"],
 					sdk_version: "core_platform",
+					min_sdk_version: "29",
 					updatable: true,
 				}`,
 			expectedError: "Updatable apps must use stable SDKs",
@@ -350,9 +358,20 @@
 					name: "foo",
 					srcs: ["a.java"],
 					updatable: true,
+					min_sdk_version: "29",
 				}`,
 			expectedError: "Updatable apps must use stable SDK",
 		},
+		{
+			name: "Must specify min_sdk_version",
+			bp: `android_app {
+					name: "app_without_min_sdk_version",
+					srcs: ["a.java"],
+					sdk_version: "29",
+					updatable: true,
+				}`,
+			expectedError: "updatable apps must set min_sdk_version.",
+		},
 	}
 
 	for _, test := range testCases {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 40cfe4f..28a2c8a 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -62,6 +62,10 @@
 	}
 }
 
+func init() {
+	dexpreopt.DexpreoptRunningInSoong = true
+}
+
 func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
 	global := dexpreopt.GetGlobalConfig(ctx)