MCPcopy Index your code
hub / github.com/Kernel-SU/binder_rs

github.com/Kernel-SU/binder_rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
540 symbols 1,088 edges 40 files 200 documented · 37%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

binder_rs

The stub libbinder_ndk.so in ndk's sysroot hides some apis, so that we cannot link our libbiner_rs to it. However, we can rebuild a stub so to make linker happy. The stub source is generated from symbols.txt, whose contents are extracted from prebuilt libbinder_ndk.so from aosp-mainline.

The libbinder_ndk.so is introduced in api-29, you need to compile it with specified target api level. The compilation won't failed if api is lower than 29, because we build the dynamic library on ourselves.

We use ndk-build to build the stub so, ANDROID_NDK_HOME must be set in your env !

sys/src/include_* from platform/frameworks/native/libs/binder/ndk

Example

  1. Build

    cargo ndk -t arm64-v8a --platform=29 --bindgen build

  2. Push file to phone

    adb push target/aarch64-linux-android/debug/binder-example /data/local/tmp

  3. Run 2 adb shell

    Run server:

    adb shell su -c /data/local/tmp/binder-example server

    Run client:

    adb shell su -c /data/local/tmp/binder-example client

Test

  1. Build

    cargo ndk -t arm64-v8a --platform=29 --bindgen build

  2. Push files to phone

    adb push target/aarch64-linux-android/debug/binder-tests /data/local/tmp

  3. Build unittest binary

    cargo ndk -t arm64-v8a --platform=29 --bindgen test --bin binder-tests --no-run

  4. Push files to phone

    adb push target/aarch64-linux-android/debug/deps/binder_tests-acf830ec15b8864e /data/local/tmp

  5. Run test

    adb shell cd /data/local/tmp/ && su -c ./binder_tests-acf830ec15b8864e

    if you see error like this

    CANNOT LINK EXECUTABLE "/data/local/tmp/binder_tests-acf830ec15b8864e": cannot locate symbol "AIBinder_DeathRecipient_setOnUnlinked" referenced by "/data/local/tmp/binder_tests-acf830ec15b8864e"...

    This is because your android version is too low, the source is from android-mainline. You can try in avd, with Android U

Extension points exported contracts — how you extend this code

AsNative (Interface)
Trait for transparent Rust wrappers around android C++ native types. The pointer return by this trait's methods should [8 …
binder/src/binder.rs
ITest (Interface)
Trivial testing binder interface [3 implementers]
tests/src/main.rs
IRemoteService (Interface)
(no doc) [4 implementers]
example/src/IRemoteService.rs
Serialize (Interface)
A struct whose instances can be written to a [`Parcel`]. Might be able to hook this up as a serde backend in the future? [18 …
binder/src/parcel/parcelable.rs
IATest (Interface)
Async trivial testing binder interface [2 implementers]
tests/src/main.rs
IRemoteServiceAsync (Interface)
(no doc) [1 implementers]
example/src/IRemoteService.rs
Deserialize (Interface)
A struct whose instances can be restored from a [`Parcel`]. Might be able to hook this up as a serde backend in the futu [15 …
binder/src/parcel/parcelable.rs
ITestSameDescriptor (Interface)
Trivial testing binder interface [2 implementers]
tests/src/main.rs

Core symbols most depended-on inside this repo

get
called by 51
binder_ndk_sys/src/include_cpp/android/binder_auto_utils.h
write
called by 34
binder/src/parcel.rs
read
called by 33
binder/src/parcel.rs
status_result
called by 26
binder/src/error.rs
borrowed_ref
called by 23
binder/src/parcel.rs
get_data_position
called by 16
binder/src/parcel.rs
set_data_position
called by 12
binder/src/parcel.rs
clone
called by 12
binder/src/proxy.rs

Shape

Method 268
Function 170
Class 66
Interface 29
Enum 7

Languages

Rust62%
C++38%

Modules by API surface

binder_ndk_sys/src/include_cpp/android/binder_parcel_utils.h79 symbols
binder_ndk_sys/src/include_cpp/android/binder_auto_utils.h60 symbols
tests/src/main.rs54 symbols
binder/src/proxy.rs50 symbols
binder/src/parcel.rs38 symbols
binder/src/binder.rs37 symbols
binder_ndk_sys/src/include_cpp/android/binder_interface_utils.h30 symbols
binder/src/parcel/parcelable.rs27 symbols
binder/src/error.rs26 symbols
binder/src/native.rs25 symbols
example/src/IRemoteService.rs22 symbols
binder_ndk_sys/src/include_cpp/android/binder_parcelable_utils.h14 symbols

For agents

$ claude mcp add binder_rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact