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
android: add platform.android_ver() #71042
Comments
The attached patch misses a test case. Also how can we be sure that the '/system/build.prop' file may be guaranteed to exist on all android devices ? |
This path is hard-coded in BioniC [1]. Though I can't find a document/relevant source codes to guarantee 'ro.build.version.release' and 'ro.build.version.sdk' is always in /system/build.prop And the format of build.prop is not exactly INI. It supports 'import' clauses. See [2] and load_properties() function in [3] Other options include calling [1] https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/_system_properties.h |
The android/api-level.h header exists at all the android API levels and define __ANDROID_API__ as, for example at level 21: #define __ANDROID_API__ 21 So it is possible to get the sdk version from here, and maybe forget about the release version. |
Isn't this macro used in compile time? I thought android_ver() aims to check runtime versions. |
If the file is guaranteed to exist on most modern Android platforms, this sounds like a good approach. Perhaps you could add support to fallback to running getprop instead, if the file doesn't exist or cannot be parsed ?! |
Some screenshots showing different file contents:
I think exposing
|
I have a WIP patch. [1] It's based on Shiz's patch [2]. [1] https://github.com/yan12125/python3-android/blob/cpython-hg/mk/python/android-misc.patch |
Several questions on implementation:
Some related Android source codes, as my implementation basis:
[1] rave-engine/python3-android#10 (comment) |
On 04.05.2016 21:47, Chi Hsuan Yen wrote:
According to http://www.droid-life.com/tag/distribution/ the Jelly
Agreed. |
Version 2 attached. Removed ro.build.version.full. |
Android framework provides an SDK_INT field [1], which parses the value of [1] https://android.googlesource.com/platform/frameworks/base/+/e8579b12a3c5be5fef25fc5a1c8c2c9d43e49347/core/java/android/os/Build.java#183 |
IMHO returning an integer for the sdk field would be better. The patch could use shutil.which() to avoid subprocess calls when getprop is not available. It would be better to use a 'try/except ValueError' clause instead of isdigit(). The OSError and UnicodeDecodeError exceptions should not be masked, as well as ValueError if sdk cannot be parsed as an int. |
Version 3. Still using a try-catch clause to enclose the subprocess call, as _syscmd_ver does the same thing. |
The ro.kernel.qemu property is set to 1 on an Android emulator and 0 otherwise. I think it should be added to the list. On some threading tests where the switch interval is set to one microsecond, it is necessary to set the switch interval to a higher value when running on the qemu emulator, see the three issues: |
I guess ro.kernel.qemu is not generic enough to be an item in android_ver(). In tests you can simply use _android_getprop() |
Agreed, and it is not part of the versioning scheme either. |
I see Xavier de Gaye uses sysconfig.get_config_var('ANDROID_API_LEVEL') is various patches. That's OK if the build-time target API level of CPython matches runtime Android API level. Does CPython force API level matching? If so this issue is no longer necessary. |
ANDROID_API_LEVEL can only be used in the Python test suite and platform.android_ver() must be used in the standard library. The reason why ANDROID_API_LEVEL can be used in the tests instead of using the runtime API level is that the Python test suite purpose is not to test the compatibilities betweeen all the possible subjacent bionic libc(s) and the tests need only be run on the platform for which they have been built. platform.android_ver() is a welcome enhancement, and since we are at 3.6 beta now it's too late for 3.6 and it will be implemented in 3.7. Sorry about this delay. |
Chromium still uses the private __system_property_get() function: https://chromium.googlesource.com/chromium/+/trunk/base/sys_info_android.cc I would prefer a C function call rather than spawning a subprocess, just to get a value. But the function seems private, and I see discussion about removal of the function... |
I cannot find a reference to the "build.prop" file in the Android documentation but google answers at the question ' what is "build.prop"':
and stackoverflow is thriving with questions on how to edit this file. The file contains part of the information returned by the getprop command and all the information we are needing here. Here is its content and access rights on an android-24-x86_64 emulator: generic_x86_64:/data/local/tmp/python $ ls -al /system/build.prop # begin build properties
# autogenerated by buildinfo.sh
ro.build.id=NYC
ro.build.display.id=sdk_phone_x86_64-userdebug 7.0 NYC 4174735 test-keys
ro.build.version.incremental=4174735
ro.build.version.sdk=24
ro.build.version.preview_sdk=0
ro.build.version.codename=REL
ro.build.version.all_codenames=REL
ro.build.version.release=7.0
ro.build.version.security_patch=2017-06-05
ro.build.version.base_os=
ro.build.date=Wed Jul 12 19:46:52 UTC 2017
ro.build.date.utc=1499888812
ro.build.type=userdebug
ro.build.user=android-build
ro.build.host=wphl5.hot.corp.google.com
ro.build.tags=test-keys
ro.build.flavor=sdk_phone_x86_64-userdebug
ro.product.model=Android SDK built for x86_64
ro.product.brand=Android
ro.product.name=sdk_phone_x86_64
ro.product.device=generic_x86_64
ro.product.board=
# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,
# use ro.product.cpu.abilist instead.
ro.product.cpu.abi=x86_64
ro.product.cpu.abilist=x86_64,x86
ro.product.cpu.abilist32=x86
ro.product.cpu.abilist64=x86_64
ro.product.manufacturer=unknown
ro.product.locale=en-US
ro.wifi.channels=
ro.board.platform=
# ro.build.product is obsolete; use ro.product.device
ro.build.product=generic_x86_64
ro.product.cpu.abilist=x86_64,x86
ro.product.cpu.abilist32=x86
ro.product.cpu.abilist64=x86_64
ro.product.manufacturer=unknown
ro.product.locale=en-US
ro.wifi.channels=
ro.board.platform=
# ro.build.product is obsolete; use ro.product.device
ro.build.product=generic_x86_64
# Do not try to parse description, fingerprint, or thumbprint
ro.build.description=sdk_phone_x86_64-userdebug 7.0 NYC 4174735 test-keys
ro.build.fingerprint=Android/sdk_phone_x86_64/generic_x86_64:7.0/NYC/4174735:userdebug/test-keys
ro.build.characteristics=emulator
# end build properties
#
# from build/target/board/generic_x86_64/system.prop
#
#
# system.prop for generic sdk
# rild.libpath=/system/lib/libreference-ril.so #
# ADDITIONAL_BUILD_PROPERTIES
#
ro.config.notification_sound=OnTheHunt.ogg
ro.config.alarm_alert=Alarm_Classic.ogg
persist.sys.dalvik.vm.lib.2=libart.so
dalvik.vm.isa.x86_64.variant=x86_64
dalvik.vm.isa.x86_64.features=default
dalvik.vm.isa.x86.variant=x86
dalvik.vm.isa.x86.features=default
dalvik.vm.lockprof.threshold=500
xmpp.auto-presence=true
ro.config.nocheckin=yes
net.bt.name=Android
dalvik.vm.stack-trace-file=/data/anr/traces.txt |
"-rw-r--r-- 1 root root 2083 2017-07-12 22:01 /system/build.prop" so |
Yes, and fall back to spawning getprop if that fails. In the following link Robin Gawenda is reporting that /system/build.prop is world readable on all the devices he checked: https://stackoverflow.com/questions/9937099/how-to-get-the-build-prop-values |
I suggest to start simple. Parsing a text file is simple, spawning a subprocess can have annoying side effects :-( |
xdegaye mannequin commentedApr 26, 2016
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: