2012-10-24 17:45:23 +00:00
|
|
|
/* Copyright 2008 The Android Open Source Project
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-01-30 06:32:32 +00:00
|
|
|
#include <string.h>
|
2012-10-24 17:45:23 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "binder.h"
|
|
|
|
|
2014-01-30 14:07:34 +00:00
|
|
|
uint32_t svcmgr_lookup(struct binder_state *bs, uint32_t target, const char *name)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2014-01-30 14:07:34 +00:00
|
|
|
uint32_t handle;
|
2012-10-24 17:45:23 +00:00
|
|
|
unsigned iodata[512/4];
|
|
|
|
struct binder_io msg, reply;
|
|
|
|
|
|
|
|
bio_init(&msg, iodata, sizeof(iodata), 4);
|
|
|
|
bio_put_uint32(&msg, 0); // strict mode header
|
|
|
|
bio_put_string16_x(&msg, SVC_MGR_NAME);
|
|
|
|
bio_put_string16_x(&msg, name);
|
|
|
|
|
|
|
|
if (binder_call(bs, &msg, &reply, target, SVC_MGR_CHECK_SERVICE))
|
|
|
|
return 0;
|
|
|
|
|
2014-01-30 14:07:34 +00:00
|
|
|
handle = bio_get_ref(&reply);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-01-30 14:07:34 +00:00
|
|
|
if (handle)
|
|
|
|
binder_acquire(bs, handle);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
binder_done(bs, &msg, &reply);
|
|
|
|
|
2014-01-30 14:07:34 +00:00
|
|
|
return handle;
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:07:34 +00:00
|
|
|
int svcmgr_publish(struct binder_state *bs, uint32_t target, const char *name, void *ptr)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2013-12-19 09:11:41 +00:00
|
|
|
int status;
|
2012-10-24 17:45:23 +00:00
|
|
|
unsigned iodata[512/4];
|
|
|
|
struct binder_io msg, reply;
|
|
|
|
|
|
|
|
bio_init(&msg, iodata, sizeof(iodata), 4);
|
|
|
|
bio_put_uint32(&msg, 0); // strict mode header
|
|
|
|
bio_put_string16_x(&msg, SVC_MGR_NAME);
|
|
|
|
bio_put_string16_x(&msg, name);
|
|
|
|
bio_put_obj(&msg, ptr);
|
|
|
|
|
|
|
|
if (binder_call(bs, &msg, &reply, target, SVC_MGR_ADD_SERVICE))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
status = bio_get_uint32(&reply);
|
|
|
|
|
|
|
|
binder_done(bs, &msg, &reply);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned token;
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct binder_state *bs;
|
2014-01-30 14:07:34 +00:00
|
|
|
uint32_t svcmgr = BINDER_SERVICE_MANAGER;
|
|
|
|
uint32_t handle;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
bs = binder_open(128*1024);
|
2014-01-30 15:16:45 +00:00
|
|
|
if (!bs) {
|
|
|
|
fprintf(stderr, "failed to open binder driver\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
while (argc > 0) {
|
|
|
|
if (!strcmp(argv[0],"alt")) {
|
2014-01-30 14:07:34 +00:00
|
|
|
handle = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
|
|
|
|
if (!handle) {
|
2012-10-24 17:45:23 +00:00
|
|
|
fprintf(stderr,"cannot find alt_svc_mgr\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-01-30 14:07:34 +00:00
|
|
|
svcmgr = handle;
|
|
|
|
fprintf(stderr,"svcmgr is via %x\n", handle);
|
2012-10-24 17:45:23 +00:00
|
|
|
} else if (!strcmp(argv[0],"lookup")) {
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr,"argument required\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-01-30 14:07:34 +00:00
|
|
|
handle = svcmgr_lookup(bs, svcmgr, argv[1]);
|
|
|
|
fprintf(stderr,"lookup(%s) = %x\n", argv[1], handle);
|
2012-10-24 17:45:23 +00:00
|
|
|
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;
|
|
|
|
}
|