linkedin / dexmaker

A utility for doing compile or runtime code generation targeting Android's Dalvik VM
Apache License 2.0
1.86k stars 248 forks source link

Allow mocking of native methods #162

Open the-felipeal opened 4 years ago

the-felipeal commented 4 years ago

For example, Binder.getCallindUid()

kkoser commented 4 years ago

This seems possible, I can think of a few ways to do it - 1) you can override native methods from parent classes with non-parent subclasses, and 2) You could code generate a native library and load that, and have it provide a faked implementation.

Where it gets more difficult is with the binder example you mentioned - Note that you can't mock final or static methods before Android P (where the mockito-inline support was added). I'm not sure the JVMTI implementation would play with native methods, that still needs more investigation.

I don't know when we'll have time to work on this however. I'll take this to my team and see if anyone can work on it, but also if anyone is interested in trying it out we're open to PRs!