This is an archive of the discontinued LLVM Phabricator instance.

Implement __isOSVersionAtLeast for Android
ClosedPublic

Authored by jiyong on Aug 26 2020, 1:31 AM.

Details

Summary

Add the implementation of __isOSVersionAtLeast for Android. Currently,
only the major version is checked against the API level of the platform
which is an integer. The API level is retrieved by reading the system
property ro.build.version.sdk (and optionally ro.build.version.codename
to see if the platform is released or not).

Patch by jiyong@google.com

Bug: 150860940
Bug: 134795810
Test: m

Diff Detail

Event Timeline

srhines created this revision.Aug 26 2020, 1:31 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added subscribers: Restricted Project, krytarowski, tschuett. · View Herald Transcript
srhines requested review of this revision.Aug 26 2020, 1:31 AM
jiyong added a subscriber: jiyong.Aug 27 2020, 1:37 AM
jiyong commandeered this revision.Aug 27 2020, 2:04 AM
jiyong added a reviewer: srhines.

Thanks Stephen. I now have the account here and ready to contribute. Let me fix the clang format errors.

jiyong updated this revision to Diff 288237.Aug 27 2020, 2:05 AM

Re-formatted using clang-format

jiyong added a comment.Sep 2 2020, 1:15 AM

Hi Reviewers,

This is a gentle ping asking for review.

jiyong updated this revision to Diff 290216.Sep 7 2020, 2:15 AM

Handle the case when the system properties don't exist (e.g. on host)

srhines removed a reviewer: llvm-commits.
srhines added a subscriber: llvm-commits.
srhines accepted this revision.Sep 9 2020, 1:56 AM

Sorry, Jiyong, I had forgotten to subscribe llvm-commits when I first uploaded this (because it's part of compiler-rt and doesn't seem to have a default rule to add them). In any case, this patch LGTM, and I am going to go ahead and approve it since this only affects Android. Let's give it 24 hours for anyone else to comment before committing though (especially since I messed up with the original upload/review).

This revision is now accepted and ready to land.Sep 9 2020, 1:56 AM
jiyong added a comment.Sep 9 2020, 2:25 AM

No worries, and thanks for reviewing. I will wait for one another day.

+24 hours has passed. Stephen, could you land this? (I don't think I have the privileged to do so, do I?)

This revision was automatically updated to reflect the committed changes.
MaskRay added a subscriber: MaskRay.EditedSep 15 2020, 3:27 PM

Hi, git commits can set author and committer separately, please see https://llvm.org/docs/DeveloperPolicy.html#commit-messages https://llvm.org/docs/DeveloperPolicy.html#attribution-of-changes :)

Bug: 150860940
Bug: 134795810
Test: m

And this is not Gerrit. Such tags in the description can be distracting.

smeenai added a subscriber: smeenai.Sep 6 2023, 3:18 PM
smeenai added inline comments.
compiler-rt/lib/builtins/os_version_check.c
232–234

This is inconsistent with android_get_device_api_level, which returns -1 on failure instead (per https://developer.android.com/ndk/reference/group/apilevels#android_get_device_api_level). How come a different behavior was chosen here? I don't know if it's at all likely for reading this property to fail anyway, but if it does, it seems confusing for an availability check to go in the opposite direction as a manual check based on android_get_device_api_level.

Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2023, 3:18 PM
jiyong added inline comments.Sep 6 2023, 6:43 PM
compiler-rt/lib/builtins/os_version_check.c
232–234

How come a different behavior was chosen here?

The reasoning behind this code is that the exceptional case has to be resolved by this runtime library (in isOSVersionAtLeast), not by application, and isOSVersionAtLeast has no means of reporting an error; it returns boolean. So, when ro.build.version.sdk doesn't exist isOSVersionAtLeast can't help but return one of these three:

(1) return false regardless of Major

(2) return Major >= a_reasonably_old_api_level

(3) return true regardless of Major

We thought (1) is bad because it renders all APIs as unavailable, which probably doesn't reflect the reality. (2) is not good because people have different opinions on what a_reasonably_old_api_level should be. So we picked (3) as the least worst option.

The situation is different when users use android_get_device_api_level manually. If it returns -1, they can fallback to check the availability of the symbol manually by calling dlsym or similar.


Nevertheless, practically speaking, ro.build.version.sdk is guaranteed to exist. So this behavior won't be triggered anyway.

smeenai added inline comments.Sep 6 2023, 7:04 PM
compiler-rt/lib/builtins/os_version_check.c
232–234

That makes sense, thanks.