diff options
author | 2022-05-06 03:17:24 +0000 | |
---|---|---|
committer | 2022-05-06 03:17:24 +0000 | |
commit | beccdcdff207de34e10d17bb8928ad5d1c512bf3 (patch) | |
tree | a24188901a595593d210996c715f526bbc2c642b /apex/apex.go | |
parent | 08f7eadceec856c359614701da06ec95bf88449c (diff) | |
parent | 17e2290e9febcb84786498b427d1234a19f9e74c (diff) |
Merge "Revert "Append APEX version instead of build ID for APK-in-APEX ...""
Diffstat (limited to 'apex/apex.go')
-rw-r--r-- | apex/apex.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/apex/apex.go b/apex/apex.go index 73a3fc2c7..b3398156d 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -19,6 +19,7 @@ package apex import ( "fmt" "path/filepath" + "regexp" "sort" "strings" @@ -1653,7 +1654,20 @@ type androidApp interface { var _ androidApp = (*java.AndroidApp)(nil) var _ androidApp = (*java.AndroidAppImport)(nil) -const APEX_VERSION_PLACEHOLDER = "__APEX_VERSION_PLACEHOLDER__" +func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string { + buildId := ctx.Config().BuildId() + + // The build ID is used as a suffix for a filename, so ensure that + // the set of characters being used are sanitized. + // - any word character: [a-zA-Z0-9_] + // - dots: . + // - dashes: - + validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`) + if !validRegex.MatchString(buildId) { + ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId) + } + return buildId +} func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile { appDir := "app" @@ -1664,7 +1678,7 @@ func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexF // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed // so that PackageManager correctly invalidates the existing installed apk // in favour of the new APK-in-APEX. See bugs for more information. - dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+APEX_VERSION_PLACEHOLDER) + dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx)) fileToCopy := aapp.OutputFile() af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp) @@ -1903,7 +1917,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // suffixed so that PackageManager correctly invalidates the // existing installed apk in favour of the new APK-in-APEX. // See bugs for more information. - appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+APEX_VERSION_PLACEHOLDER) + appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx)) af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap) af.certificate = java.PresignedCertificate filesInfo = append(filesInfo, af) |