GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — android: add platform.android_ver() · Issue #71042 · python/cpython

android: add platform.android_ver() #71042

New issue
Copy link
New issue
Copy link
Closed
#116674
Closed
android: add platform.android_ver()#71042
#116674
Copy link
Labels
3.7 (EOL)end of lifeend of lifeOS-androidbuildThe build process and cross-buildThe build process and cross-buildstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

xdegaye
mannequin
opened on Apr 26, 2016
Issue body actions
BPO 26855
Nosy @malemburg, @vstinner, @pmp-p, @Fak3, @moreati, @yan12125
Files
  • platform.patch
  • android_ver.patch
  • android_ver.patch: Patch version 2
  • android_ver.patch: Patch version 3
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2016-04-26.13:18:31.861>
    labels = ['3.7', 'type-feature', 'library', 'build']
    title = 'android: add platform.android_ver()'
    updated_at = <Date 2019-12-10.08:09:38.614>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2019-12-10.08:09:38.614>
    actor = 'xdegaye'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Cross-Build']
    creation = <Date 2016-04-26.13:18:31.861>
    creator = 'xdegaye'
    dependencies = []
    files = ['42606', '42721', '42723', '42813']
    hgrepos = []
    issue_num = 26855
    keywords = ['patch']
    message_count = 23.0
    messages = ['264277', '264317', '264369', '264373', '264374', '264376', '264377', '264852', '264854', '264856', '265145', '265294', '265307', '267409', '267413', '267415', '280147', '280166', '307662', '307667', '307672', '307685', '308040']
    nosy_count = 6.0
    nosy_names = ['lemburg', 'vstinner', 'pmpp', 'Roman.Evstifeev', 'Alex.Willmer', 'yan12125']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue26855'
    versions = ['Python 3.7']

    Linked PRs

    • gh-71042: Add platform.android_ver #116674

    Activity

    Next
    1. xdegaye commented on Apr 26, 2016

      @xdegaye
      xdegayemannequin
      on Apr 26, 2016
      MannequinAuthor
      More actions

      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 ?
      It is difficult to get a reliable information on the android infrastructure when the information does not relate to the java libraries.

    2. xdegaye
      added
      buildThe build process and cross-buildThe build process and cross-build
      type-featureA feature request or enhancementA feature request or enhancement
      on Apr 26, 2016
    3. yan12125 commented on Apr 26, 2016

      @yan12125
      yan12125mannequin
      on Apr 26, 2016
      Mannequin
      More actions

      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 getprop via subprocess or using C level function __system_property_get(). The first approach should always work. It's just somewhat tricky on Android 4.1 [4]. For the second option, a bad news is that it's a private API and was just removed from the latest NDK. Chromium has a workaround for that [5] and CPython may use similar approaches.

      [1] https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/_system_properties.h
      [2] http://forum.xda-developers.com/android/general/explanation-build-prop-values-t3069341
      [3] https://android.googlesource.com/platform/system/core/+/master/init/property_service.cpp
      [4] rave-engine/python3-android#10 (comment)
      [5] https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/keQP6L9aVyU

    4. xdegaye commented on Apr 27, 2016

      @xdegaye
      xdegayemannequin
      on Apr 27, 2016
      MannequinAuthor
      More actions

      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.

    5. yan12125 commented on Apr 27, 2016

      @yan12125
      yan12125mannequin
      on Apr 27, 2016
      Mannequin
      More actions

      Isn't this macro used in compile time? I thought android_ver() aims to check runtime versions.

    6. malemburg commented on Apr 27, 2016

      @malemburg
      malemburg
      on Apr 27, 2016
      Member
      More actions

      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 ?!

    7. malemburg commented on Apr 27, 2016

      @malemburg
      malemburg
      on Apr 27, 2016
      Member
      More actions

      Some screenshots showing different file contents:

      • http://www1-lw.xda-cdn.com/files/2013/12/tweak-your-samsung-galaxy-s3s-performance-with-these-build-prop-android-hacks.w654.jpg
      • http://media.apcmag.com/wp-content/uploads/sites/20/2014/04/buildprop-text-file.jpg
      • http://i.imgur.com/hZXQaX9.png

      I think exposing codename and incremental may also make sense to get a complete picture.

      ro.product also has a lot of useful entries which could be used for some of the other platform APIs such as uname().

    8. yan12125 commented on Apr 27, 2016

      @yan12125
      yan12125mannequin
      on Apr 27, 2016
      Mannequin
      More actions

      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
      [2] https://github.com/rave-engine/python3-android/blob/9bb6420317922c07df405315eea040f9301f7eca/mk/python/3.4.3/python-3.4.3-android-misc.patch

    9. xdegaye
      changed the title [-]add platform.android_ver() for android[/-] [+]android: add platform.android_ver()[/+] on May 3, 2016
    10. yan12125 commented on May 4, 2016

      @yan12125
      yan12125mannequin
      on May 4, 2016
      Mannequin
      More actions

      Several questions on implementation:

      1. Should Android 4.1 supported? If not pass_fds and logics for deriving it can be removed.
      2. I can't find ro.build.version.full on any device/emulator I have access to. Maybe it should be removed due to low popularity?

      Some related Android source codes, as my implementation basis:

      1. Android 4.1's ANDROID_PROPERTY_WORKSPACE: https://android.googlesource.com/platform/bionic/+/android-4.1.1_r1/libc/bionic/system_properties.c#55
      2. The Android Framework assumes property values to be valid UTF-8: https://android.googlesource.com/platform/frameworks/base/+/android-5.1.1_r37/core/jni/android_os_SystemProperties.cpp#49. In fact if I feed a malformed /system/build.prop to DalvikVM, it crashes [1]
      3. Google's Android Compatibility Test Suite (CTS) [2] assumes getprop binary is in $PATH and can be executed: https://android.googlesource.com/platform/cts/+/android-5.1.1_r37/tests/tests/os/src/android/os/cts/BuildTest.java#110

      [1] rave-engine/python3-android#10 (comment)
      [2] https://source.android.com/compatibility/cts/

    11. malemburg commented on May 4, 2016

      @malemburg
      malemburg
      on May 4, 2016
      Member
      More actions

      On 04.05.2016 21:47, Chi Hsuan Yen wrote:

      1. Should Android 4.1 supported? If not pass_fds and logics for deriving it can be removed.

      According to http://www.droid-life.com/tag/distribution/ the Jelly
      Bean versions (4.1, 4.2 and 4.3) still have a sizable market
      share, so if it's not too much trouble, I think supporting 4.1 would
      be a plus.

      1. I can't find ro.build.version.full on any device/emulator I have access to. Maybe it should be removed due to low popularity?

      Agreed.

    12. yan12125 commented on May 4, 2016

      @yan12125
      yan12125mannequin
      on May 4, 2016
      Mannequin
      More actions

      Version 2 attached. Removed ro.build.version.full.

    13. yan12125 commented on May 8, 2016

      @yan12125
      yan12125mannequin
      on May 8, 2016
      Mannequin
      More actions

      Android framework provides an SDK_INT field [1], which parses the value of ro.build.version.sdk and defaults to 0 if failed [2]. Should android_ver() return an integer for the sdk field, too? It simplifies the usage in bpo-26935 and similar ones.

      [1] https://android.googlesource.com/platform/frameworks/base/+/e8579b12a3c5be5fef25fc5a1c8c2c9d43e49347/core/java/android/os/Build.java#183
      [2] https://android.googlesource.com/platform/frameworks/base/+/e8579b12a3c5be5fef25fc5a1c8c2c9d43e49347/core/jni/android_os_SystemProperties.cpp#66

    14. xdegaye commented on May 11, 2016

      @xdegaye
      xdegayemannequin
      on May 11, 2016
      MannequinAuthor
      More actions

      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.

    15. 10 remaining items

    16. vstinner commented on Dec 5, 2017

      @vstinner
      vstinner
      on Dec 5, 2017
      Member
      More actions

      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...

    17. xdegaye commented on Dec 5, 2017

      @xdegaye
      xdegayemannequin
      on Dec 5, 2017
      MannequinAuthor
      More actions

      I cannot find a reference to the "build.prop" file in the Android documentation but google answers at the question ' what is "build.prop"':

      The “build.prop” file is a system file that exists on every Android device. The file contains build information and other system properties which are used throughout the operating system.
      

      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
      -rw-r--r-- 1 root root 2083 2017-07-12 22:01 /system/build.prop
      generic_x86_64:/data/local/tmp/python $ cat /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
      rild.libargs=-d /dev/ttyS0

      #
      # 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
    18. vstinner commented on Dec 5, 2017

      @vstinner
      vstinner
      on Dec 5, 2017
      Member
      More actions

      "-rw-r--r-- 1 root root 2083 2017-07-12 22:01 /system/build.prop" so
      anyone can *read* the file. Maybe we can write a cheap parser for it,
      instead of spawning a subprocess or relying on a private function
      which may be removed in the near future?

    19. xdegaye commented on Dec 5, 2017

      @xdegaye
      xdegayemannequin
      on Dec 5, 2017
      MannequinAuthor
      More actions

      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

    20. vstinner commented on Dec 11, 2017

      @vstinner
      vstinner
      on Dec 11, 2017
      Member
      More actions

      Yes, and fall back to spawning getprop if that fails.

      I suggest to start simple. Parsing a text file is simple, spawning a subprocess can have annoying side effects :-(

    21. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    22. encukou
      added this to Unsupported platformson Feb 1, 2024
    23. mhsmith commented on Feb 8, 2024

      @mhsmith
      mhsmith
      on Feb 8, 2024
      Member
      More actions

      We're currently discussing PEP 738, which contains a different specification for android_ver. Please post any comments here:

      • PEP 738: Android support, draft 2 peps#3651
    24. encukou
      added
      OS-android
      on Mar 20, 2024
    25. vstinner
      closed this as completedin #116674on Mar 27, 2024
    26. vstinner
      added a commit that references this issue on Mar 27, 2024

      gh-71042: Add `platform.android_ver` (#116674)

      74c8568
    27. github-project-automation
      moved this to Done in Unsupported platformson Mar 27, 2024
    28. NGRsoftlab
      added 2 commits that reference this issue on Apr 2, 2024

      Squashed commit of the following:

      1b5fe4c

      Squashed commit of the following:

      a016a54
    29. diegorusso
      added a commit that references this issue on Apr 17, 2024

      pythongh-71042: Add `platform.android_ver` (python#116674)

      1acc356
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeend of lifeOS-androidbuildThe build process and cross-buildThe build process and cross-buildstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

      Projects

      • Unsupported platforms
        Status
        Done
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.