APEX uses the latest version of the stub
Previously when an APEX whose min_sdk_version is set is linked to an
external library providing multiple versions of stubs, the
maximum version that is less than or equal to the min_sdk_version was
chosen. For example, if the versions of a library stubs are 28, 29, 30,
and 31, then APEX with min_sdk_version: 29 linked to the version 29 of
the stub.
This was to ensure that the APEX doesn't use any new APIs whose
existence can't be guaranteed.
This however imposes a severe restriction that the APEX can never use
new APIs even when the APIs are actually available: i.e. when the
APEX is running on a newer platform.
With the recent work about unguarded availability, using the future APIs
became much safer. When you use an API that is newer than your
min_sdk_version, the API is automatically declared as a weak symbol
(thus no link error at runtime), while the call to API is guaranteed to
be guarded with the `__builtin_available(...)` macro.
So, there really is no reason to use the old version of the stub. We can
always use the latest version of stub safely.
Bug: N/A
Test: m
Change-Id: Iaac0d8761d8929154527dc2e861a51ae31e23d49
diff --git a/cc/cc.go b/cc/cc.go
index 11d8718..47a1f8a 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2420,36 +2420,6 @@
}
}
-// Returns the highest version which is <= maxSdkVersion.
-// For example, with maxSdkVersion is 10 and versionList is [9,11]
-// it returns 9 as string. The list of stubs must be in order from
-// oldest to newest.
-func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedStubLibrary,
- maxSdkVersion android.ApiLevel) (SharedStubLibrary, error) {
-
- for i := range stubsInfo {
- stubInfo := stubsInfo[len(stubsInfo)-i-1]
- var ver android.ApiLevel
- if stubInfo.Version == "" {
- ver = android.FutureApiLevel
- } else {
- var err error
- ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
- if err != nil {
- return SharedStubLibrary{}, err
- }
- }
- if ver.LessThanOrEqualTo(maxSdkVersion) {
- return stubInfo, nil
- }
- }
- var versionList []string
- for _, stubInfo := range stubsInfo {
- versionList = append(versionList, stubInfo.Version)
- }
- return SharedStubLibrary{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
-}
-
// Convert dependencies to paths. Returns a PathDeps containing paths
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
@@ -2633,16 +2603,12 @@
useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
}
- // when to use (unspecified) stubs, check min_sdk_version and choose the right one
+ // when to use (unspecified) stubs, use the latest one.
if useStubs {
- sharedLibraryStubsInfo, err :=
- c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedStubLibraries, c.apexSdkVersion)
- if err != nil {
- ctx.OtherModuleErrorf(dep, err.Error())
- return
- }
- sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
- depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
+ stubs := sharedLibraryStubsInfo.SharedStubLibraries
+ toUse := stubs[len(stubs)-1]
+ sharedLibraryInfo = toUse.SharedLibraryInfo
+ depExporterInfo = toUse.FlagExporterInfo
}
}