int main() { struct binder_state *bs = binder_open(128*1024); if (!bs) { fprintf(stderr, "failed to open binder driver\n"); return -1; } svcmgr_publish(bs, BINDER_SERVICE_MANAGER, "com.example.backlight_service", &token); binder_loop(bs, my_handler); return 0; }
int main(int argc, char **argv) { struct binder_state *bs; uint32_t svcmgr = BINDER_SERVICE_MANAGER; uint32_t handle; bs = binder_open("/dev/binder", 128*1024); if (!bs) { fprintf(stderr, "failed to open binder driver\n"); return -1; } argc--; argv++; while (argc > 0) { if (!strcmp(argv[0],"alt")) { handle = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr"); if (!handle) { fprintf(stderr,"cannot find alt_svc_mgr\n"); return -1; } svcmgr = handle; fprintf(stderr,"svcmgr is via %x\n", handle); } else if (!strcmp(argv[0],"lookup")) { if (argc < 2) { fprintf(stderr,"argument required\n"); return -1; } handle = svcmgr_lookup(bs, svcmgr, argv[1]); fprintf(stderr,"lookup(%s) = %x\n", argv[1], handle); argc--; argv++; } else if (!strcmp(argv[0],"publish")) { if (argc < 2) { fprintf(stderr,"argument required\n"); return -1; } svcmgr_publish(bs, svcmgr, argv[1], &token); argc--; argv++; } else { fprintf(stderr,"unknown command %s\n", argv[0]); return -1; } argc--; argv++; } return 0; }
int main(int argc, char **argv) { struct binder_state *bs; void *svcmgr = BINDER_SERVICE_MANAGER; bs = binder_open(128*1024); if (binder_become_context_manager(bs)) { ALOGE("cannot become context manager (%s)\n", strerror(errno)); return -1; } svcmgr_handle = svcmgr; binder_loop(bs, svcmgr_handler); return 0; }
int main(int argc, char **argv) { struct binder_state *bs; void *svcmgr = BINDER_SERVICE_MANAGER; bs = binder_open(128*1024); // listen to the binder to request if (binder_become_context_manager(bs)) { return -1; } svcmgr_handle = svcmgr; binder_loop(bs, svcmgr_handler); return 0; }
int main(int argc, char **argv) { int fd; struct binder_state *bs; void *svcmgr = BINDER_SERVICE_MANAGER; bs = binder_open(128*1024); LOG_IF_RETURN(bs == NULL, "ERR: bs is NULL!"); argc--; argv++; while (argc > 0) { if (!strcmp(argv[0],"alt")) { void *ptr = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr"); if (!ptr) { fprintf(stderr,"cannot find alt_svc_mgr\n"); return -1; } svcmgr = ptr; fprintf(stderr,"svcmgr is via %p\n", ptr); } else if (!strcmp(argv[0],"lookup")) { void *ptr; if (argc < 2) { fprintf(stderr,"argument required\n"); return -1; } ptr = svcmgr_lookup(bs, svcmgr, argv[1]); fprintf(stderr,"lookup(%s) = %p\n", argv[1], ptr); argc--; argv++; } else if (!strcmp(argv[0],"publish")) { if (argc < 2) { fprintf(stderr,"argument required\n"); return -1; } svcmgr_publish(bs, svcmgr, argv[1], &token); argc--; argv++; } else { fprintf(stderr,"unknown command %s\n", argv[0]); return -1; } argc--; argv++; } return 0; }
int main(int argc, char **argv) { struct binder_state *bs; bs = binder_open(128*1024); if (!bs) { ALOGE("failed to open binder driver\n"); return -1; } if (binder_become_context_manager(bs)) { ALOGE("cannot become context manager (%s)\n", strerror(errno)); return -1; } selinux_enabled = is_selinux_enabled(); sehandle = selinux_android_service_context_handle(); selinux_status_open(true); if (selinux_enabled > 0) { if (sehandle == NULL) { ALOGE("SELinux: Failed to acquire sehandle. Aborting.\n"); abort(); } if (getcon(&service_manager_context) != 0) { ALOGE("SELinux: Failed to acquire service_manager context. Aborting.\n"); abort(); } } union selinux_callback cb; cb.func_audit = audit_callback; selinux_set_callback(SELINUX_CB_AUDIT, cb); cb.func_log = selinux_log_callback; selinux_set_callback(SELINUX_CB_LOG, cb); binder_loop(bs, svcmgr_handler); return 0; }
int main(int argc, char **argv) { int fd; struct binder_state *bs; uint32_t svcmgr = BINDER_SERVICE_MANAGER; uint32_t handle; int ret; bs = binder_open(128*1024); if (!bs) { fprintf(stderr, "failed to open binder driver\n"); return -1; } /* add service */ ret = svcmgr_publish(bs, svcmgr, "hello", hello_service_handler); if (ret) { fprintf(stderr, "failed to publish hello service\n"); return -1; } ret = svcmgr_publish(bs, svcmgr, "goodbye", goodbye_service_handler); if (ret) { fprintf(stderr, "failed to publish goodbye service\n"); } #if 0 while(1) { /* read data */ /* parse data, and process */ /* reply */ } #endif binder_loop(bs, test_server_handler); return 0; }
int open_driver() { return binder_open(128*1024); }
/* ./test_client hello * ./test_client hello <name> */ int main(int argc, char **argv) { int fd; struct binder_state *bs; uint32_t svcmgr = BINDER_SERVICE_MANAGER; uint32_t handle; int ret; if(argc < 2){ fprintf(stderr, "Usage:\n"); fprintf(stderr, "%s <hello|goodbye>\n", argv[0]); fprintf(stderr, "%s <hello|goodbye> <name>\n", argv[0]); return -1; } bs = binder_open(128*1024); if (!bs) { fprintf(stderr, "failed to open binder driver\n"); return -1; } g_bs = bs; handle = svcmgr_lookup(bs, svcmgr, "goodbye"); if(!handle){ fprintf(stderr, "failed to get goodbye service\n"); return -1; } g_goodbye_handle = handle; fprintf(stderr, "Handle for goodbye service = %d\n", g_goodbye_handle); /* get service */ handle = svcmgr_lookup(bs, svcmgr, "hello"); if(!handle){ fprintf(stderr, "failed to get hello service\n"); return -1; } g_hello_handle = handle; fprintf(stderr, "Handle for hello service = %d\n", g_hello_handle); /* send data to server */ if(!strcmp(argv[1], "hello")) { if(argc == 2){ sayhello(); }else if(argc == 3){ ret = sayhello_to(argv[2]); fprintf(stderr, "get ret of sayhello_to = %d\n",ret); } } else if(!strcmp(argv[1], "goodbye")) { if(argc == 2){ saygoodbye(); }else if(argc == 3){ ret = saygoodbye_to(argv[2]); fprintf(stderr, "get ret of saygoodbye_to = %d\n",ret); } } binder_release(bs, handle); return 0; }