[英]What's the most efficient way to transfer data/packets between native code and Java code in Android
I'm going to write an Android App to read raw packet from native code with raw socket interface. 我将编写一个Android应用程序,以使用原始套接字接口从本机代码读取原始数据包。 My phone is rooted so my native code can access to the native code by using runtime.exec("su").
我的手机已扎根,因此我的本机代码可以使用runtime.exec(“ su”)访问本机代码。 But I don't know how to efficient transfer packets between the native code and Java code.
但是我不知道如何在本机代码和Java代码之间高效地传输数据包。 (In this case, the native code and Java code are running in different processes) Since my App must process the raw packets from the native code as efficient as possible, I need a "fast tunnel" between them.
(在这种情况下,本机代码和Java代码在不同的进程中运行)由于我的应用程序必须尽可能高效地处理本机代码中的原始数据包,因此我需要它们之间的“快速通道”。 Any ideas or suggestions?
有什么想法或建议吗?
PS I have tired Android NDK, but in NDK, native code and Java code are running in the same process so the native code cannot have the root privilege to access raw socket. PS:我对Android NDK感到厌倦,但是在NDK中,本机代码和Java代码在同一进程中运行,因此本机代码不能具有访问原始套接字的root特权。
The solution is: create an agent at native layer so that it can talk to your java activity via JNI. 解决方案是:在本机层创建一个代理,以便它可以通过JNI与您的Java活动对话。 Then hook up the agent and your native service by using IPC (binder).
然后使用IPC(活页夹)连接代理和本机服务。
One issue: it is not convenient to pass complex data structure via JNI. 一个问题:通过JNI传递复杂的数据结构并不方便。 So step back, why do you want to pass entire packets?
那么退后一步,为什么要传递整个数据包? Can you process the packets at native layer and submit the result (eg, integers) only?
您能否在本机层处理数据包并仅提交结果(例如整数)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.