Support SHA minSdkVersion in APK in APEX

Bug: 266903788
Test: rm -fr out/dist
      UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true TARGET_BUILD_APPS="com.google.android.rkpd" vendor/google/build/mainline_modules_bundles.sh
      # Without this change it fails, with this change it passes at
      # which point run the following.
      mkdir contents
      cd contents
      unzip ../out/dist/dev_keys_signed/com.google.android.rkpd/com.google.android.rkpd.apks
      deapexer extract standalones/standalone-x86.apex apex-contents
      aapt2 dump badging apex-contents/priv-app/rkpdapp.google@*/rkpdapp.google.apk  | grep Version
      # The sdkVersion and targetSdkVersion should both be set to SHA
      # versions.
Change-Id: I9ca54affd30f0a6cf561f1274b991d39e7cf1bce
(cherry picked from commit 730d0c437a)
Merged-In: I9ca54affd30f0a6cf561f1274b991d39e7cf1bce
This commit is contained in:
Paul Duffin 2023-02-01 12:12:51 +00:00 committed by Cherrypicker Worker
parent 57e2bd728a
commit a03f1265fb
1 changed files with 15 additions and 5 deletions

View File

@ -2309,12 +2309,22 @@ def GetMinSdkVersionInt(apk_name, codename_to_api_level_map):
try:
return int(version)
except ValueError:
# Not a decimal number. Codename?
if version in codename_to_api_level_map:
return codename_to_api_level_map[version]
# Not a decimal number.
#
# It could be either a straight codename, e.g.
# UpsideDownCake
#
# Or a codename with API fingerprint SHA, e.g.
# UpsideDownCake.e7d3947f14eb9dc4fec25ff6c5f8563e
#
# Extract the codename and try and map it to a version number.
split = version.split(".")
codename = split[0]
if codename in codename_to_api_level_map:
return codename_to_api_level_map[codename]
raise ExternalError(
"Unknown minSdkVersion: '{}'. Known codenames: {}".format(
version, codename_to_api_level_map))
"Unknown codename: '{}' from minSdkVersion: '{}'. Known codenames: {}".format(
codename, version, codename_to_api_level_map))
def SignFile(input_name, output_name, key, password, min_api_level=None,