Alternative to SystemProperties reflection for getting system properties in android

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Alternative to SystemProperties reflection for getting system properties in android

pendyala syam

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative to SystemProperties reflection for getting system properties in android

Dylan Deng
google doesn't recommend getting system properties in the application. Or you can sign your apk with platform signature, then you can call SystemProperties.get() directly.

在 2018年9月15日星期六 UTC+8上午6:39:04,pendyala syam写道:

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in <a href="https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;" onclick="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;">https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative to SystemProperties reflection for getting system properties in android

florian.limberger
In reply to this post by pendyala syam
You could perhaps use native code, have a look at $ANDROID_SDK_ROOT/ndk-bundle/sysroot/usr/include/sys/system_properties.h.

On Saturday, September 15, 2018 at 12:39:04 AM UTC+2, pendyala syam wrote:

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in <a href="https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;" onclick="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;">https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative to SystemProperties reflection for getting system properties in android

pendyala syam
Thanks florian for the suggestion. 

In http://androidxref.com/9.0.0_r3/xref/bionic/libc/include/sys/system_properties.h, there is a comment "Deprecated" on top of the function declaration of __system_property_get. Does it mean, it is going to be deprecated in near future?

On Mon, Sep 17, 2018 at 11:10 PM <[hidden email]> wrote:
You could perhaps use native code, have a look at $ANDROID_SDK_ROOT/ndk-bundle/sysroot/usr/include/sys/system_properties.h.

On Saturday, September 15, 2018 at 12:39:04 AM UTC+2, pendyala syam wrote:

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative to SystemProperties reflection for getting system properties in android

florian.limberger
I think it is already deprecated, but the comment also suggests an alternative: __system_property_read_callback.

On Wednesday, September 19, 2018 at 12:31:36 AM UTC+2, pendyala syam wrote:
Thanks florian for the suggestion. 

In <a href="http://androidxref.com/9.0.0_r3/xref/bionic/libc/include/sys/system_properties.h" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fxref%2Fbionic%2Flibc%2Finclude%2Fsys%2Fsystem_properties.h\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNErami6pjcZs1hI3NrKrUgnbCan3A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fxref%2Fbionic%2Flibc%2Finclude%2Fsys%2Fsystem_properties.h\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNErami6pjcZs1hI3NrKrUgnbCan3A&#39;;return true;">http://androidxref.com/9.0.0_r3/xref/bionic/libc/include/sys/system_properties.h, there is a comment "Deprecated" on top of the function declaration of <a href="http://androidxref.com/9.0.0_r3/s?defs=__system_property_get&amp;project=bionic" style="color:rgb(32,32,98)" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fs%3Fdefs%3D__system_property_get%26project%3Dbionic\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxz9MOmZyGmFUYBbewHfqf3WyrZg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fs%3Fdefs%3D__system_property_get%26project%3Dbionic\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxz9MOmZyGmFUYBbewHfqf3WyrZg&#39;;return true;">__system_property_get. Does it mean, it is going to be deprecated in near future?

On Mon, Sep 17, 2018 at 11:10 PM <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">florian....@...> wrote:
You could perhaps use native code, have a look at $ANDROID_SDK_ROOT/ndk-bundle/sysroot/usr/include/sys/system_properties.h.

On Saturday, September 15, 2018 at 12:39:04 AM UTC+2, pendyala syam wrote:

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in <a href="https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;" onclick="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;">https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-platfo...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-...@googlegroups.com.
Visit this group at <a href="https://groups.google.com/group/android-platform" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/android-platform&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/android-platform&#39;;return true;">https://groups.google.com/group/android-platform.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative to SystemProperties reflection for getting system properties in android

Liran Barsisa
In reply to this post by pendyala syam
Can you please share a sample code of how to use it via Kotlin/Java?

On Wednesday, September 19, 2018 at 1:31:36 AM UTC+3, pendyala syam wrote:
Thanks florian for the suggestion. 

In <a href="http://androidxref.com/9.0.0_r3/xref/bionic/libc/include/sys/system_properties.h" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fxref%2Fbionic%2Flibc%2Finclude%2Fsys%2Fsystem_properties.h\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNErami6pjcZs1hI3NrKrUgnbCan3A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fxref%2Fbionic%2Flibc%2Finclude%2Fsys%2Fsystem_properties.h\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNErami6pjcZs1hI3NrKrUgnbCan3A&#39;;return true;">http://androidxref.com/9.0.0_r3/xref/bionic/libc/include/sys/system_properties.h, there is a comment "Deprecated" on top of the function declaration of <a href="http://androidxref.com/9.0.0_r3/s?defs=__system_property_get&amp;project=bionic" style="color: rgb(32, 32, 98); --darkreader-inline-color:#9eb6df;" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fs%3Fdefs%3D__system_property_get%26project%3Dbionic\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxz9MOmZyGmFUYBbewHfqf3WyrZg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fandroidxref.com%2F9.0.0_r3%2Fs%3Fdefs%3D__system_property_get%26project%3Dbionic\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxz9MOmZyGmFUYBbewHfqf3WyrZg&#39;;return true;" data-darkreader-inline-color="">__system_property_get. Does it mean, it is going to be deprecated in near future?

On Mon, Sep 17, 2018 at 11:10 PM <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">florian....@...> wrote:
You could perhaps use native code, have a look at $ANDROID_SDK_ROOT/ndk-bundle/sysroot/usr/include/sys/system_properties.h.

On Saturday, September 15, 2018 at 12:39:04 AM UTC+2, pendyala syam wrote:

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties class and call get method with key.
  2. call adb shell command "getprop" using Runtime exec.

Using the sample app, I observed that option#1(took 1msec) is very faster than option#2(13msecs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in <a href="https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;" onclick="this.href=&#39;https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces&#39;;return true;">https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?


Does google recommend any efficient alternative to SystemProperties reflection and getprop methods for getting system properties??

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="GBlT4Q0bCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-...@googlegroups.com.
Visit this group at <a href="https://groups.google.com/group/android-platform" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/android-platform&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/android-platform&#39;;return true;">https://groups.google.com/group/android-platform.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/16131d65-68f4-4102-abf9-31a632a1d453o%40googlegroups.com.