Giter Club home page Giter Club logo

binderdemo's Introduction

This is a bare bones example of how to use Android IPC binders from native C++ code. For some high-level explanations see the following two blog posts:

Quick overview on how to build the code:

  • This code depends on the parts of Android that are not included in the NDK, so you'll need to repo sync and build a complete image to have all the dependencies in place. For details, see:
  • cd <RepoTop>
  • source build/envsetup.sh
  • lunch
  • cd <RepoTop>/external
  • git clone https://github.com/gburca/BinderDemo.git
  • cd BinderDemo
  • mm
  • The binary should be in <RepoTop>/out/target/product/*/system/bin/binder. Copy it to /system/bin/ on the phone.

Test the binary:

  • adb logcat -v time binder_demo:* *:S
  • adb shell binder
  • adb shell binder 456

The adb logcat -v time binder_demo:* *:S should show:

01-04 12:36:01.453 D/binder_demo( 7575): We're the service
01-04 12:36:01.454 D/binder_demo( 7575): IDemo::IDemo()
01-04 12:36:01.457 D/binder_demo( 7575): Demo service is now ready
01-04 12:36:07.658 D/binder_demo( 7577): We're the client: 456
01-04 12:36:07.660 D/binder_demo( 7577): IDemo::IDemo()
01-04 12:36:07.660 D/binder_demo( 7577): BpDemo::BpDemo()
01-04 12:36:07.660 D/binder_demo( 7577): BpDemo::alert()
01-04 12:36:07.661 D/binder_demo( 7575): BnDemo::onTransact(1) 17
01-04 12:36:07.661 D/binder_demo( 7575): Demo::alert()
01-04 12:36:07.661 D/binder_demo( 7575): BnDemo::onTransact(2) 16
01-04 12:36:07.661 D/binder_demo( 7575): BnDemo::onTransact got 456
01-04 12:36:07.661 D/binder_demo( 7575): Demo::push(456)
01-04 12:36:07.662 D/binder_demo( 7577): BpDemo::push(456)
01-04 12:36:07.662 D/binder_demo( 7575): BnDemo::onTransact(3) 16
01-04 12:36:07.662 D/binder_demo( 7575): Demo::add(456, 5)
01-04 12:36:07.662 D/binder_demo( 7575): BnDemo::onTransact add(456, 5) = 461
01-04 12:36:07.662 D/binder_demo( 7577): BpDemo::add transact reply
01-04 12:36:07.662 D/binder_demo( 7577): BpDemo::add(456, 5) = 461 (status: 0)
01-04 12:36:07.662 D/binder_demo( 7577): Addition result: 456 + 5 = 461
01-04 12:36:07.662 D/binder_demo( 7577): IDemo::~IDemo()

The adb shell binder should show:

Parcel(
  0x00000000: 00400000 00000004 00650044 006f006d '[email protected].'
  0x00000010: 00000000 00000010 00680054 00200065 '........T.h.e. .'
  0x00000020: 006c0061 00720065 00200074 00740073 'a.l.e.r.t. .s.t.'
  0x00000030: 00690072 0067006e 00000000          'r.i.n.g.....    ')
Demo::alert()
Parcel(
  0x00000000: 00400000 00000004 00650044 006f006d '[email protected].'
  0x00000010: 00000000 000001c8                   '........        ')
Demo::push(456)
Parcel(NULL)
Parcel(
  0x00000000: 00400000 00000004 00650044 006f006d '[email protected].'
  0x00000010: 00000000 000001c8 00000005          '............    ')
Demo::add(456, 5)
Parcel(NULL)

The adb shell binder 456 should show:

We're the client: 456
BpDemo::push parcel to be sent:
Parcel(
  0x00000000: 00400000 00000004 00650044 006f006d '[email protected].'
  0x00000010: 00000000 000001c8                   '........        ')
BpDemo::push parcel reply:
Parcel(NULL)
BpDemo::add parcel to be sent:
Parcel(
  0x00000000: 00400000 00000004 00650044 006f006d '[email protected].'
  0x00000010: 00000000 000001c8 00000005          '............    ')
Parcel(000001cd    '....')

The server added 5 to our 456 and returned 461 (0x01cd).

The code in this project is Copyright(C) by Gabriel Burca and released under the GPL (http://www.gnu.org/copyleft/gpl.html) license.

binderdemo's People

Contributors

eldarz avatar gburca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

binderdemo's Issues

Fail to compile

I try to compile the codes with ndk-build, but it seems that it cannot find the libs like utils/RefBase.h. Could you give out some details about how to compile the codes?

Getting a crash while running the code in Android Q OS

Hello, I followed the instruction for building it and then I pushed the "binder" executable to /system/bin
adb root && adb remount was done beforehand.

However, when I executed the command "adb shell binder" I got the following message:

adb shell binder
CANNOT LINK EXECUTABLE "binder": cannot locate symbol "_ZN7android23sp_report_stack_pointerEv" referenced by "/system/bin/binder"...

I do not know how to fix this problem. Can you please help me?

Thank you
Sarbojit

unable to compile

Hello
I am trying to compile the BinderDemo but I wasn't successful.
My steps were exactly

mkdir android_source
cd android_source/
repo init -u https://android.googlesource.com/platform/manifest
repo sync
source build/envsetup.sh
lunch
make binder
cd external/
git clone https://github.com/gburca/BinderDemo.git
cd BinderDemo
mm

The build was successful but when I try to run the binder executable on the android device, I get the following error

130|root@generic:/ # binder
CANNOT LINK EXECUTABLE: cannot locate symbol "__aeabi_memclr4" referenced by "binder"...

Any ideas?

Doesn't work without root

It appears that neither the service nor the client work without root.... Is there a way to register the service so that it can work without root?

Linker errors

Hi - Thanks a lot for putting it up together.

Initially I ran into multiple compilation issues. But I have the android source code so I Imported lot of files(folders full of headers) and got through it.

In linker error, it gave multiple errors. I was able to find libutil and libcutil from NDK and get through it. However my whole machine does not have libbinder. So cannot get through it. I have api 19. Do you know how to resolve this liner error?

Regards,
Vishal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.