Repository navigation
gh-71042: Add platform.android_ver
#116674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ead6dcb
8934a4e
4dca7c4
4108dfc
646441b
4f65e8e
9fd7f44
b64f1f5
53e6511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,9 +544,10 @@ def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')): | |
|
|
||
|
|
||
| AndroidVer = collections.namedtuple( | ||
| "AndroidVer", "release api_level manufacturer model device") | ||
| "AndroidVer", "release api_level manufacturer model device is_emulator") | ||
|
|
||
| def android_ver(release="", api_level=0, manufacturer="", model="", device=""): | ||
| def android_ver(release="", api_level=0, manufacturer="", model="", device="", | ||
| is_emulator=False): | ||
| if sys.platform == "android": | ||
| try: | ||
| from ctypes import CDLL, c_char_p, create_string_buffer | ||
|
|
@@ -560,10 +561,13 @@ def android_ver(release="", api_level=0, manufacturer="", model="", device=""): | |
| system_property_get.argtypes = (c_char_p, c_char_p) | ||
|
|
||
| def getprop(name, default): | ||
| PROP_VALUE_MAX = 92 # From sys/system_properties.h | ||
| # https://android.googlesource.com/platform/bionic/+/refs/tags/android-5.0.0_r1/libc/include/sys/system_properties.h#39 | ||
| PROP_VALUE_MAX = 92 | ||
| buffer = create_string_buffer(PROP_VALUE_MAX) | ||
| length = system_property_get(name.encode("UTF-8"), buffer) | ||
| if length == 0: | ||
| # This API doesn’t distinguish between an empty property and | ||
| # a missing one. | ||
| return default | ||
| else: | ||
| return buffer.value.decode("UTF-8", "backslashreplace") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen such strings, but this function is likely to be used when building error reports, so perfect round-tripping is less important than making sure it doesn't cause any errors itself. For that reason, I'd prefer not to use |
||
|
|
@@ -573,8 +577,10 @@ def getprop(name, default): | |
| manufacturer = getprop("ro.product.manufacturer", manufacturer) | ||
| model = getprop("ro.product.model", model) | ||
| device = getprop("ro.product.device", device) | ||
| is_emulator = getprop("ro.kernel.qemu", "0") == "1" | ||
|
|
||
| return AndroidVer(release, api_level, manufacturer, model, device) | ||
| return AndroidVer( | ||
| release, api_level, manufacturer, model, device, is_emulator) | ||
|
|
||
|
|
||
| ### System name aliasing | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.