I tried to access the GPIO on the Raspberry Pi with Android stuff using the NDK, but after several attempts, I always find some kind of security wall that prevents me from accessing it.
Motivation is the slow speed that I get from GPIO using the Java API. As a base link, I managed to turn it on and off at about 2 kHz, which turned out to be the poorest among this list . See Also What is Android Things Raspberry Pi GPIO max frequency? where there is still no answer and where I added a comment about java speed. In fact, this work was motivated by the results that I got when checking this issue.
The best approach is still trying something similar to what is required for sysfs under Debian. In this case, the code looks honest, but after starting as root, installing the application as a system application (moving it to / system / app) and chmod a + rw has several different things under /sys/class/gpio/ and /sys/class/gpio/gpio24/ as well as /dev/gpiomem is what I got:
01-27 12:54:47.069 8412 8412 I NativeHelper: Call native = hello from helper java class 01-27 12:54:47.079 8412 8412 I NativeHelper: Open pin true 01-27 12:54:47.080 8412 8412 F libc : Fatal signal 4 (SIGILL), code 1, fault addr 0xaf2e039c in tid 8412 (le.thingssample) 01-27 12:54:47.081 128 128 W : debuggerd: handling request: pid=8412 uid=10028 gid=10028 tid=8412 01-27 12:54:47.066 8412 8412 I le.thingssample: type=1400 audit(0.0:211): avc: denied { write } for name="export" dev="sysfs" ino=854 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1 01-27 12:54:47.076 8412 8412 I le.thingssample: type=1400 audit(0.0:212): avc: denied { open } for path="/sys/class/gpio/export" dev="sysfs" ino=854 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1 01-27 12:54:47.166 8427 8427 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 01-27 12:54:47.166 8427 8427 F DEBUG : Build fingerprint: 'generic/iot_rpi3/rpi3:7.0/NIF73/3565696:userdebug/test-keys' 01-27 12:54:47.166 8427 8427 F DEBUG : Revision: '0' 01-27 12:54:47.166 8427 8427 F DEBUG : ABI: 'arm' 01-27 12:54:47.167 8427 8427 F DEBUG : pid: 8412, tid: 8412, name: le.thingssample >>> com.amazingapps.sample.thingssample <<< 01-27 12:54:47.167 8427 8427 F DEBUG : signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0xaf2e039c 01-27 12:54:47.167 8427 8427 F DEBUG : r0 00000000 r1 b1f5e59f r2 b1f5e59f r3 af2e1c55 01-27 12:54:47.167 8427 8427 F DEBUG : r4 00000000 r5 be8e35fc r6 acca3230 r7 be8e35d8 01-27 12:54:47.167 8427 8427 F DEBUG : r8 be8e36f8 r9 acc85400 sl 00000000 fp be8e3684 01-27 12:54:47.168 8427 8427 F DEBUG : ip be8e3590 sp be8e3598 lr ae7fbd2b pc af2e039c cpsr 60000030 01-27 12:54:47.170 8427 8427 F DEBUG : 01-27 12:54:47.170 8427 8427 F DEBUG : backtrace: 01-27 12:54:47.170 8427 8427 F DEBUG :
By chmod a+rw /sys/class/gpio/export , at least I got the difference and could open and close the output, confirmed by the return value of the method, as well as checking the creation of /sys/class/gpio/gpio24 .
I am trying to use Raspberry Pi 3 with the following code: https://github.com/fmatosqg/androidthings_ndk/tree/SO_question
In another approach, I tried to load libperipheralman.so directly in java in the hope of making calls to its functions (obviously, where the GPIO setValue () lives), but this time I ran into another problem where a subset of the libraries was refused to load which Any security issue. See the Nougat documentation about them, which does not allow developers to access all .so for backward / future compatibility purposes.
I assume that any implementation that skips using Java VM / Dalvik can also potentially bring me closer to my goal, which gets decent GPIO speed on .apk, but I don't know if any of the approaches that work on rpi3 work + debian can be used here.