Alternative to SystemProperties reflection for getting system properties in android

1,492 views
Skip to first unread message

pendyala syam

unread,
Sep 14, 2018, 6:39:04 PM9/14/18
to android-platform

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

florian....@inovex.de

unread,
Sep 17, 2018, 1:40:01 PM9/17/18
to android-platform
You could perhaps use native code, have a look at $ANDROID_SDK_ROOT/ndk-bundle/sysroot/usr/include/sys/system_properties.h.

Dylan Deng

unread,
Sep 17, 2018, 1:40:01 PM9/17/18
to android-platform
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写道:

pendyala syam

unread,
Sep 18, 2018, 6:31:36 PM9/18/18
to android-...@googlegroups.com
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?

--
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 android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

florian....@inovex.de

unread,
Sep 19, 2018, 12:20:16 PM9/19/18
to android-platform
I think it is already deprecated, but the comment also suggests an alternative: __system_property_read_callback.

Liran Barsisa

unread,
Aug 2, 2020, 4:48:57 PM8/2/20
to android-platform
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 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 <florian....@inovex.de> 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 android-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages