bc8-android官方,bctest.c - Android社区 - https://www.androidos.net.cn/

#include #include "binder.h"

uint32_t svcmgr_lookup(struct binder_state *bs, uint32_t target, const char *name)

{

uint32_t handle;

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;

handle = bio_get_ref(&reply);

if (handle)

binder_acquire(bs, handle);

binder_done(bs, &msg, &reply);

return handle;

}

int svcmgr_publish(struct binder_state *bs, uint32_t target, const char *name, void *ptr)

{

int status;

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;

uint32_t svcmgr = BINDER_SERVICE_MANAGER;

uint32_t handle;

bs = binder_open(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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值