Code Monkey home page Code Monkey logo

simplendkbinderdemo's Introduction

Simple NDKBinder Demo

Caution: AServiceManager_getService() isn't stable ABI

This demo has been tested on Android 11. If you want to run on different Android version, you have to figure out the transact code of broadcastIntent in IActivityManager.aidl.

Introduction

This is a simple demo shows one possible way that two processes or more can do binder IPC purely using NDKBinder without the help of JNI.

But how?

The key point is that how native server can publish their service & native client can get it.

After doing some research, I found two possible ways:

  1. Do it like the native codes in Android Framework does.

    It's impossible in userspace because those APIs isn't exported to NDK & some require privilege.

  2. Using BroadcastReceiver to help exchange binder

    Parcel.writeStrongBinder transfers Binder object into flatten_binder. The kernel driver finds it & creates the reference of binder for the client so that client can talk to the server directly.

    I tried implement bindService() first, but it isn't an easy way to do this.

    And I found the Shizuku implement a command line tool in JAVA with the help of BroadcastReceiver

By the way, NDKBinder from Android 10 (API 29) provide us the code we need to build Parcel & do binder transaction.

However, the NDKBinder Demo here only creates the Parcel in native and Java does the rest.

Luckily, this answer on Stackoverflow shows that we can get the binder to the ActivityManager in native, the possibility to get two processes exchange their binder.

Todo

  1. Figure out how binder really works

  2. Figure out the format of the parcel or make the Android Framework's Parcel available under NDK.

    The parcel used by broadcastIntent() works in a weired way.

    For example, it will get broken if I change Intent's mPackage field.

  3. Support for API <= 29

    Try to implement it without the help of NDKBinder.

simplendkbinderdemo's People

Contributors

teddynight avatar

Watchers

 avatar  avatar

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.