Cómo hacer GPIO en Android Cosas sin pasar por Java
He estado intentando acceder a GPIO en Raspberry Pi con Android usando NDK, pero después de probar varios enfoques, siempre encuentro algún tipo de muro de seguridad que me impide acceder.
La motivación es la lenta velocidad que obtengo de GPIO usando la API de Java. Como referencia básica, pude activarlo y desactivarlo a aproximadamente 2KHz, que es el más pobre entreesta lista. Ver también¿Qué es la frecuencia máxima de Android Things Raspberry Pi GPIO?, donde hasta ahora no hay respuesta y donde agregué un comentario sobre la velocidad de Java. De hecho, este trabajo fue motivado por los resultados que obtuve al verificar esa pregunta.
El mejor enfoque hasta ahora es intentar algo similar a lo que tomaría para sysfs en Debian. Hasta ese punto, el código parece justo, pero después de ejecutarse como root, instalar la aplicación como aplicación del sistema (moviéndolo a / system / app) y chmod a + rw varias cosas diferentes en ambos/sys/class/gpio/
y/sys/class/gpio/gpio24/
y también/dev/gpiomem
esto fue lo que obtuve:
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 : #00 pc 0000139c /data/app/com.amazingapps.sample.thingssample-1/lib/arm/libsample.so (Java_com_amazingapps_sample_thingssample_ndk_NativeHelper_doAll+59)
01-27 12:54:47.170 8427 8427 F DEBUG : #01 pc 002c8cb3 /data/app/com.amazingapps.sample.thingssample-1/oat/arm/base.odex (offset 0x2af000)
01-27 12:54:48.133 408 8432 W ActivityManager: Force finishing activity com.amazingapps.sample.thingssample/.view.MainActivity
01-27 12:54:48.137 128 128 W : debuggerd: resuming target 8412
01-27 12:54:48.138 408 427 I BootReceiver: Copying /data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
01-27 12:54:48.228 8433 8433 W crash_reporter: Received crash notification for app_process32[8412] sig 4, user 10028 (handling)
01-27 12:54:48.233 8433 8433 I crash_reporter: State of crashed process [8412]: S (sleeping)
01-27 12:54:48.226 8433 8433 I crash_reporter: type=1400 audit(0.0:213): avc: denied { search } for name="8412" dev="proc" ino=214991 scontext=u:r:crash_reporter:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=dir permissive=1
01-27 12:54:48.226 8433 8433 I crash_reporter: type=1400 audit(0.0:214): avc: denied { read } for name="exe" dev="proc" ino=217417 scontext=u:r:crash_reporter:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=lnk_file permissive=1
01-27 12:54:48.226 8433 8433 I crash_reporter: type=1400 audit(0.0:215): avc: denied { read } for scontext=u:r:crash_reporter:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=file permissive=1
01-27 12:54:48.226 8433 8433 I crash_reporter: type=1400 audit(0.0:216): avc: denied { open } for path="/proc/8412/status" dev="proc" ino=216902 scontext=u:r:crash_reporter:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=file permissive=1
01-27 12:54:48.226 8433 8433 I crash_reporter: type=1400 audit(0.0:217): avc: denied { getattr } for path="/proc/8412/status" dev="proc" ino=216902 scontext=u:r:crash_reporter:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=file permissive=1
01-27 12:54:48.672 408 422 W ActivityManager: Activity pause timeout for ActivityRecord{f2233fb u0 com.amazingapps.sample.thingssample/.view.MainActivity t86 f}
Porchmod a+rw /sys/class/gpio/export
al menos obtuve una diferencia y pude abrir y cerrar el pin, verificado por el valor de retorno del método y también verificando la creación de/sys/class/gpio/gpio24
.
Estoy probando una Raspberry Pi 3 con el siguiente código:https://github.com/fmatosqg/androidthings_ndk/tree/SO_question
En otro enfoque intenté cargarlibperipheralman.so
directamente en Java con la esperanza de hacer llamadas a sus funciones (aparentemente ahí es donde vive GPIO setValue ()), pero esta vez me encontré con un tipo diferente de problema en el que un subconjunto de las bibliotecas no pudo cargar algún problema de seguridad. Consulte la documentación de Nougat sobre ellos, que no permite a los desarrolladores acceder a todos .so debido a propósitos de compatibilidad con versiones anteriores / futuras.
Supongo que cualquier implementación que omita el uso de Java VM / Dalvik también tiene el potencial de acercarme a mi objetivo, que es obtener una velocidad GPIO decente en un .apk, pero no sé si alguno de los enfoques que funcionan en rpi3 + Debian se puede usar aquí.