[SuperSU] AnkitChowdhury:
Hello [MENTION=631273]Chainfire[/MENTION], I'm the dev of the Game Controller 2 Touch series. My app has been having issues with Android M+. It works perfectly with Lollipop.

My app uses uinput module to create a Virtual Touch Screen and later uses the corresponding event file to inject touch actions. In order to open and write to uinput I was having to use supolicy --live. I've been monitoring the supolicy output and it returns ok for everything. Yet my app fails to open the uinput module. I'm using JNI.

Below I'm providing the supolicy patches I'm using and the corresponding output.

Input

"id",
"supolicy --live 'allow untrusted_app uhid_device chr_file { ioctl read write getattr lock append open }'",
"supolicy --live 'allow appdomain input_device dir { open read write search ioctl }'",
"supolicy --live 'allow appdomain input_device chr_file { ioctl read write getattr lock append open }'"

Output

Root? Yes
uid=0(root) gid=0(root) groups=0(root) context=u:r:init:s0
supolicy v2.67 (ndk:armeabi-v7a) - Copyright (C) 2014-2016 - Chainfire

Patching policy ...
-allow:untrusted_app:uhid_device:chr_file:ioctl=ok
-allow:untrusted_app:uhid_device:chr_file:read=ok
-allow:untrusted_app:uhid_device:chr_file:write=ok
-allow:untrusted_app:uhid_device:chr_file:getattr=ok
-allow:untrusted_app:uhid_device:chr_file:lock=ok
-allow:untrusted_app:uhid_device:chr_file:append=ok
-allow:untrusted_app:uhid_device:chr_file:open=ok
- Success
supolicy v2.67 (ndk:armeabi-v7a) - Copyright (C) 2014-2016 - Chainfire

Patching policy ...
-allow:appdomain:input_device:dir:open=ok
-allow:appdomain:input_device:dir:read=ok
-allow:appdomain:input_device:dir:write=ok
-allow:appdomain:input_device:dir:search=ok
-allow:appdomain:input_device:dir:ioctl=ok
- Success
supolicy v2.67 (ndk:armeabi-v7a) - Copyright (C) 2014-2016 - Chainfire

Patching policy ...
-allow:appdomain:input_device:chr_file:ioctl=ok
-allow:appdomain:input_device:chr_file:read=ok
-allow:appdomain:input_device:chr_file:write=ok
-allow:appdomain:input_device:chr_file:getattr=ok
-allow:appdomain:input_device:chr_file:lock=ok
-allow:appdomain:input_device:chr_file:append=ok
-allow:appdomain:input_device:chr_file:open=ok
- Success

Dmesg Audits

root@flo:/ # dmesg |grep "gc2t"
[16439.150543] type=1400 audit(1460671538.740:83405): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event6" dev="tmpfs" ino=6516 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16439.499694] type=1400 audit(1460671539.090:83415): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event6" dev="tmpfs" ino=6516 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16439.500060] type=1400 audit(1460671539.090:83416): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event4" dev="tmpfs" ino=6503 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16439.818206] type=1400 audit(1460671539.401:83423): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event4" dev="tmpfs" ino=6503 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16440.123992] type=1400 audit(1460671539.711:83433): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event3" dev="tmpfs" ino=6502 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16440.124511] type=1400 audit(1460671539.711:83434): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event5" dev="tmpfs" ino=7275 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16440.445800] type=1400 audit(1460671540.021:83444): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event5" dev="tmpfs" ino=7275 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16441.061614] type=1400 audit(1460671540.652:83468): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event1" dev="tmpfs" ino=7273 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16441.061950] type=1400 audit(1460671540.652:83469): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event0" dev="tmpfs" ino=7272 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0
[16441.368102] type=1400 audit(1460671540.962:83477): avc: denied { write } for
pid=11306 comm="alyst06.gc2tpro" name="event0" dev="tmpfs" ino=7272 scontext=u:r
:untrusted_app:s0:c512,c768 tcontext=u:object_r:input_device:s0 tclass=chr_file
permissive=0

JNI Code[fails & returns -1]

fd =open("/dev/uinput", O_WRONLY | O_NONBLOCK | O_CREAT);
if (fd < 0)
{
return -1;
}

More Info: chmod works on the uinput module. Yet it doesn't open via JNI.

Would be extremely grateful if you could help me out with this. Thanks in advance.