Discussion:
__system_property_get()
(too old to reply)
John Dallman
2018-11-01 18:16:46 UTC
Permalink
I need to get some kind of unique identifier for each of the Android
devices in my testing setup from native code. I need to be able to do this
on API 21 or later, on 64-bit ARM. The [ro.serialno] property will do
nicely, since that's what "adb devices" displays.

From a bit of searching, the recommended way to get system properties from
native code seems to be to use the functions in sys/system_properties.h.
__system_property_find() will find a property, and get a prop_info* for it,
but I'm floundering on how to get the string from that. The
__system_property_read_callback function only appears at API 26. The
obvious alternative is to use the deprecated __system_property_get(), but
is there a better way?
Thanks,
John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgkbiPmjhhNUshfpmnEO%2Bq4w9AYHcoGa340EGzzfZ_OMYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2018-11-01 23:32:46 UTC
Permalink
__system_property_get should be fine for serial numbers. The new APIs exist
to work around the fact that __system_property_get could only read values
up to a fixed size (and it wasn't particularly large), but that's very
unlikely to be a problem for a serial number. On the off chance it is, you
can safely assume that they won't be until those APIs are available, so you
can always dlsym __system_property_read_callback, use it if it's available,
fallback if it isn't.

That's only part of the question though. Newer versions of Android (O? N? I
don't remember) restrict access to various system properties with selinux,
and it seems the serial number is one of them (it is PII, after all). I
think you need an app permission to access it from the Java side too.

The way my test runner handles getting serial numbers for attached devices
is just with `adb devices`. That works for me because the device side of
the tests doesn't need the information, it's just for orchestration on the
host side. Not sure if that's any help for your use case.
Post by John Dallman
I need to get some kind of unique identifier for each of the Android
devices in my testing setup from native code. I need to be able to do this
on API 21 or later, on 64-bit ARM. The [ro.serialno] property will do
nicely, since that's what "adb devices" displays.
From a bit of searching, the recommended way to get system properties from
native code seems to be to use the functions in sys/system_properties.h.
__system_property_find() will find a property, and get a prop_info* for
it, but I'm floundering on how to get the string from that. The
__system_property_read_callback function only appears at API 26. The
obvious alternative is to use the deprecated __system_property_get(), but
is there a better way?
Thanks,
John
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAH1xqgkbiPmjhhNUshfpmnEO%2Bq4w9AYHcoGa340EGzzfZ_OMYg%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAH1xqgkbiPmjhhNUshfpmnEO%2Bq4w9AYHcoGa340EGzzfZ_OMYg%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGhthwRSRYsj7XKrPRgr%2B_DU%3DThfES%2BVwOEbkq4%2BjAk1ZzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
John Dallman
2018-11-02 10:07:22 UTC
Permalink
Post by 'Dan Albert' via android-ndk
__system_property_get should be fine for serial numbers. The new APIs
exist to work around the fact that __system_property_get could only read
values up to a fixed size (and it wasn't particularly large), but that's
very
Post by 'Dan Albert' via android-ndk
unlikely to be a problem for a serial number.
The longest serial-number device I have is <20 characters, so the
32-character limit looks OK.
Post by 'Dan Albert' via android-ndk
Newer versions of Android (O? N? I don't remember) restrict access to
various
Post by 'Dan Albert' via android-ndk
system properties with selinux, and it seems the serial number is one of
them

I could cope with that if there's a way to get access without rooting the
device (which I'm not forbidden, but I'd much rather avoid). But I know
very little about selinux: can you point me to a source?
Post by 'Dan Albert' via android-ndk
... device side of the tests doesn't need the information, it's just for
orchestration on the
Post by 'Dan Albert' via android-ndk
host side. Not sure if that's any help for your use case.
The output of my tests is a big plain-text file, entirely generated by my
on-device test harness, and having the device serial number in that,
obtained by the test harness, reduces the possibility for confusion.

Thanks very much,

John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgmbzmwyAdhLU0td%3DoedV2KLWbNubtGj-MYD%3DXMvZmKEEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
John Dallman
2018-11-02 15:36:03 UTC
Permalink
Post by John Dallman
Post by 'Dan Albert' via android-ndk
__system_property_get should be fine for serial numbers. The new APIs
exist to work around the fact that __system_property_get could only read
values up to a fixed size (and it wasn't particularly large), but that's
very
Post by 'Dan Albert' via android-ndk
unlikely to be a problem for a serial number.
The longest serial-number device I have is <20 characters, so the
32-character limit looks OK.
Post by 'Dan Albert' via android-ndk
Newer versions of Android (O? N? I don't remember) restrict access to
various
Post by 'Dan Albert' via android-ndk
system properties with selinux, and it seems the serial number is one of
them
I could cope with that if there's a way to get access without rooting the
device (which I'm not forbidden, but I'd much rather avoid). But I know
very little about selinux: can you point me to a source?
Post by 'Dan Albert' via android-ndk
... device side of the tests doesn't need the information, it's just for
orchestration on the
Post by 'Dan Albert' via android-ndk
host side. Not sure if that's any help for your use case.
The output of my tests is a big plain-text file, entirely generated by my
on-device test harness, and having the device serial number in that,
obtained by the test harness, reduces the possibility for confusion.
Thanks very much,
John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgm4r0W-%2BSeyXVK_HCxrtc%3DtdLNK8%3DhEwFg%2B5-BXjbz03w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
John Dallman
2018-11-02 15:51:58 UTC
Permalink
Post by John Dallman
The longest serial-number device I have is <20 characters, so the
32-character limit looks OK.

No, that's a 92-character limit, isn't it?
Post by John Dallman
Post by 'Dan Albert' via android-ndk
Newer versions of Android (O? N? I don't remember) restrict access to
various
Post by John Dallman
Post by 'Dan Albert' via android-ndk
system properties with selinux, and it seems the serial number is one of
them

Android O, it seems.
Post by John Dallman
The output of my tests is a big plain-text file, entirely generated by my
on-device test
Post by John Dallman
harness, and having the device serial number in that, obtained by the
test harness,
Post by John Dallman
reduces the possibility for confusion.
Well, it looks as if it will stop working when I move up to O.

Oh, well.

John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgk1dsex9RpZr_7EWt2UY9uBV-DArrXos8iZpuVr4Hw9xg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-11-05 12:02:45 UTC
Permalink
Post by John Dallman
The output of my tests is a big plain-text file, entirely generated by
my on-device test
Post by John Dallman
harness, and having the device serial number in that, obtained by the
test harness,
Post by John Dallman
reduces the possibility for confusion.
Well, it looks as if it will stop working when I move up to O.
An easy batch script will run adb, fetch the number, and push it as a text
file to /data/local/tmp. Now your test will easily know the ID.

BR,
Alex
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/d39d5078-4986-4572-802e-178378156cb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
John Dallman
2018-11-06 09:43:37 UTC
Permalink
Post by Alex Cohn
An easy batch script will run adb, fetch the number, and push it as a text
file to /data/local/tmp.
Now your test will easily know the ID.
I've done a bit of a variant on that, but it works fine.

Thanks,

John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgnpbTnOJLOyED7FPV9uFyctU5hgQLt10Eo77JRFt%2BL74Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...