Set version code of apex and apk based on RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION.

The build flag RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION is set up to
allow the default version code of updatable apk and apex to be
configurable per release config. Use the value from flag and remove old constant value (DefaultUpdatableModuleVersion).

Bug: 369531931
Test: presubmit
Test: flash cf and check version
Change-Id: Ia0a8634360cbe83501cdafee888678836005620f
diff --git a/android/Android.bp b/android/Android.bp
index 16a34b7..90d932c 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -105,7 +105,6 @@
         "test_asserts.go",
         "test_suites.go",
         "testing.go",
-        "updatable_modules.go",
         "util.go",
         "variable.go",
         "vintf_fragment.go",
diff --git a/android/config.go b/android/config.go
index 368e573..ebf4781 100644
--- a/android/config.go
+++ b/android/config.go
@@ -245,6 +245,13 @@
 		Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
 }
 
+func (c Config) ReleaseDefaultUpdatableModuleVersion() string {
+	if val, exists := c.GetBuildFlag("RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION"); exists {
+		return val
+	}
+	panic("RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION is missing from build flags.")
+}
+
 func (c Config) ReleaseDisableVerifyOverlaps() bool {
 	return c.config.productVariables.GetBuildFlagBool("RELEASE_DISABLE_VERIFY_OVERLAPS_CHECK")
 }
diff --git a/android/updatable_modules.go b/android/updatable_modules.go
deleted file mode 100644
index d2595ed..0000000
--- a/android/updatable_modules.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2022 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package android
-
-// This file contains branch specific constants. They are stored in a separate
-// file to minimise the potential of merge conflicts between branches when
-// the code from the package is changed.
-
-// The default manifest version for all the modules on this branch.
-// This version code will be used only if there is no version field in the
-// module's apex_manifest.json. Release branches have their version injected
-// into apex_manifest.json by the tooling and will not use the version set
-// here. Developers can also set the version field locally in the
-// apex_manifest.json to build a module with a specific version.
-//
-// The value follows the schema from go/mainline-version-codes, and is chosen
-// based on the branch such that the builds from testing and development
-// branches will have a version higher than the prebuilts.
-// Versions per branch:
-// * x-dev           - xx0090000 (where xx is the branch SDK level)
-// * AOSP            - xx9990000
-// * x-mainline-prod - xx9990000
-// * master          - 990090000
-const DefaultUpdatableModuleVersion = "352090000"
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 2b97728..aaa72be 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -6516,14 +6516,14 @@
 	`)
 
 	fooManifestRule := result.ModuleForTests("foo", "android_common_foo").Rule("apexManifestRule")
-	fooExpectedDefaultVersion := android.DefaultUpdatableModuleVersion
+	fooExpectedDefaultVersion := testDefaultUpdatableModuleVersion
 	fooActualDefaultVersion := fooManifestRule.Args["default_version"]
 	if fooActualDefaultVersion != fooExpectedDefaultVersion {
 		t.Errorf("expected to find defaultVersion %q; got %q", fooExpectedDefaultVersion, fooActualDefaultVersion)
 	}
 
 	barManifestRule := result.ModuleForTests("bar", "android_common_bar").Rule("apexManifestRule")
-	defaultVersionInt, _ := strconv.Atoi(android.DefaultUpdatableModuleVersion)
+	defaultVersionInt, _ := strconv.Atoi(testDefaultUpdatableModuleVersion)
 	barExpectedDefaultVersion := fmt.Sprint(defaultVersionInt + 3)
 	barActualDefaultVersion := barManifestRule.Args["default_version"]
 	if barActualDefaultVersion != barExpectedDefaultVersion {
diff --git a/apex/builder.go b/apex/builder.go
index 437189f..0be8026 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -359,14 +359,14 @@
 	}
 
 	manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json")
-	defaultVersion := android.DefaultUpdatableModuleVersion
+	defaultVersion := ctx.Config().ReleaseDefaultUpdatableModuleVersion()
 	if a.properties.Variant_version != nil {
 		defaultVersionInt, err := strconv.Atoi(defaultVersion)
 		if err != nil {
-			ctx.ModuleErrorf("expected DefaultUpdatableModuleVersion to be an int, but got %s", defaultVersion)
+			ctx.ModuleErrorf("expected RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION to be an int, but got %s", defaultVersion)
 		}
 		if defaultVersionInt%10 != 0 {
-			ctx.ModuleErrorf("expected DefaultUpdatableModuleVersion to end in a zero, but got %s", defaultVersion)
+			ctx.ModuleErrorf("expected RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION to end in a zero, but got %s", defaultVersion)
 		}
 		variantVersion := []rune(*a.properties.Variant_version)
 		if len(variantVersion) != 1 || variantVersion[0] < '0' || variantVersion[0] > '9' {
diff --git a/apex/testing.go b/apex/testing.go
index 3b200f0..63c5b69 100644
--- a/apex/testing.go
+++ b/apex/testing.go
@@ -16,6 +16,8 @@
 
 import "android/soong/android"
 
+const testDefaultUpdatableModuleVersion = "340090000"
+
 var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers(
 	android.FixtureRegisterWithContext(registerApexBuildComponents),
 	android.FixtureRegisterWithContext(registerApexKeyBuildComponents),
@@ -29,4 +31,5 @@
 		// Needed by prebuilt_apex.
 		"build/soong/scripts/unpack-prebuilt-apex.sh": nil,
 	}.AddToFixture(),
+	android.PrepareForTestWithBuildFlag("RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION", testDefaultUpdatableModuleVersion),
 )
diff --git a/java/app.go b/java/app.go
index 4ac42a7..9b7b7a4 100644
--- a/java/app.go
+++ b/java/app.go
@@ -586,7 +586,7 @@
 		if override := ctx.Config().Getenv("OVERRIDE_APEX_MANIFEST_DEFAULT_VERSION"); override != "" {
 			a.aapt.defaultManifestVersion = override
 		} else {
-			a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
+			a.aapt.defaultManifestVersion = ctx.Config().ReleaseDefaultUpdatableModuleVersion()
 		}
 	}
 
diff --git a/java/app_test.go b/java/app_test.go
index ec97a55..b593e29 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -530,9 +530,9 @@
 	`)
 	foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer")
 	android.AssertStringDoesContain(t,
-		"com.android.foo: expected manifest fixer to set override-placeholder-version to android.DefaultUpdatableModuleVersion",
+		"com.android.foo: expected manifest fixer to set override-placeholder-version to RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION",
 		foo.BuildParams.Args["args"],
-		fmt.Sprintf("--override-placeholder-version %s", android.DefaultUpdatableModuleVersion),
+		fmt.Sprintf("--override-placeholder-version %s", testDefaultUpdatableModuleVersion),
 	)
 }
 
diff --git a/java/testing.go b/java/testing.go
index 0c79e9f..b27e69b 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -30,6 +30,7 @@
 )
 
 const defaultJavaDir = "default/java"
+const testDefaultUpdatableModuleVersion = "340090000"
 
 // Test fixture preparer that will register most java build components.
 //
@@ -61,6 +62,7 @@
 		// Needed for the global lint checks provided from frameworks/base
 		"prebuilts/cmdline-tools/AndroidGlobalLintChecker.jar": nil,
 	}.AddToFixture(),
+	android.PrepareForTestWithBuildFlag("RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION", testDefaultUpdatableModuleVersion),
 )
 
 var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers(