Android Binder native client in C with epoll

127
October 20, 2019, at 04:30 AM

Have this code that directly accesses Binder via IOCTL:

#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>

#define BINDER_THREAD_EXIT 0x40046208ul
#define BINDER_VERSION 0xc0046209ul
int main()
{
    int fd,fd1,fd2, epfd,epfd1,epfd2;
    struct epoll_event event = { .events = EPOLLIN   };
    fd = open("/dev/binder", O_RDONLY);
    fd1 = open("/dev/random", O_RDONLY);
    epfd = epoll_create(1000);
    epfd1 = epoll_create(1000);

    if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event)) err(1, "epoll_add");
    if (epoll_ctl(epfd1, EPOLL_CTL_ADD, fd1, &event)) err(1, "epoll_add");


    //ioctl(fd, BINDER_VERSION, NULL);
    ioctl(fd, BINDER_THREAD_EXIT, NULL);
    printf("Finished here.");
}

Somehow I don't see created thread/process under thread->task_list or proc->task_list, i think at least one entry (current process) should be there:

See here:

[  642.254192] wq queue:e7ce8798
[  642.254201] epoll struct:e7ce8780
[  642.254214] wq queue:e7ce8f98
[  642.254220] epoll struct:e7ce8f80
[  642.254230] wq queue:e7ce8718
[  642.254236] epoll struct:e7ce8700
[  642.254266] binder_ioctl: 7392:7392 40046208 0
[  642.254274] iovec str size:8
[  642.254280] thread->task_list:e5389b30
[  642.254286] proc->task_list:c309d86c
[  642.254292] binder_free_thread size:252 worker_off:44
[  642.254299] freed thread:e5389b00
[  642.254736] ep_unregister_pollwait struct:e7ce8780 epi struct:e51d0480
[  642.254792] ep_unregister_pollwait struct:e7ce8f80 epi struct:e51d0a80
[  642.254799] ep_unregister_pollwait list not empty
[  642.254805] whead before
[  642.254811] my2= c0f50cc4 c0f50cc4
[  642.254817] remove wait queue:e734b994
[  642.254823] remove wait queue task list:e734b9a0
[  642.254830] ep_unregister_pollwait list not empty
[  642.254835] whead before
[  642.254841] my2= c0f50cd0 c0f50cd0
[  642.254847] remove wait queue:e734bb24
[  642.254852] remove wait queue task list:e734bb30
[  642.254863] ep_free
[  642.254873] ep_free
[  642.254881] ep_free

Below is the Java App, that behaves like I want it to see:

s3ve3g:/ # ps | grep 2140                                                    
u0_a50    2140  257   845744 36336 sys_epoll_ b4ed9114 S com.cyanogenmod.lockclock

Source of the app:

https://github.com/LineageOS/android_packages_apps_LockClock

[   53.617686] binder_ioctl: 2140:2401 40046208 0
[   53.617697] iovec str size:8
[   53.617704] thread->task_list:e5b2c030
[   53.617710] proc->task_list:e609206c
[   53.617716] p list= e609206c e50c3e7c
[   53.617722] p list= e50c5e7c e609206c
[   53.617729] binder_free_thread size:252 worker_off:44
[   53.617736] freed thread:e5b2c000
[   53.617755] ep_unregister_pollwait struct:e5f5c680 epi struct:e5f4c280
[   53.617762] ep_unregister_pollwait list not empty
[   53.617768] whead before
[   53.617773] my2= e8b10308 e8b10308
[   53.617779] remove wait queue:e5fd755c
[   53.617785] remove wait queue task list:e5fd7568
[   53.617803] ep_free

See proc->task_list entries, they're there.

I think Binder is used here:

https://github.com/LineageOS/android_packages_apps_LockClock/blob/5239d22272aa2b7a2bcf2c45482395da3e163289/src/org/lineageos/lockclock/DeviceStatusService.java

Any idea how to replicate this using C (native) code?

How to make what with Binder what com.cyanogenmod.lockclock is doing.

Thanks,

Rent Charter Buses Company
READ ALSO
Error func.apply is not a function error in react native

Error func.apply is not a function error in react native

I am trying to create a react native app for the first time and I get this weird error that I can't understandthis is my code :

250
How I can generic primary key in android room dao

How I can generic primary key in android room dao

I am trying to generic my primary key entity in dao room android, but it's failed

171
react native build release from .apk to .aab, how to send the app to the clients?

react native build release from .apk to .aab, how to send the app to the clients?

It's been so long since I develop a mobile app in react native, when I'm developing before, I usually generate a release apk and send it to my clients so that they can test it and have experienced it, but now when I build a release in react native, it returns...

133
asop build error: FAILED: out/target/product/x86_64/android_x86_64.iso

asop build error: FAILED: out/target/product/x86_64/android_x86_64.iso

I am build android x86 source code i got this error

128