我需要做的简要说明: 我修改了android框架并创建了需要与用户空间中运行的C程序进行通信的应用程序。这个C程序基本上是我写的与驱动程序和一堆API接口的存根。它在复杂性方面几乎是空的,因为它只用作隐藏机制的单个入口点,但它只有几千行。
我和我的实习导师对如何做到这一点有不同意见:
1 /应用程序和修改后的框架(客户端)使用套接字与C程序通信,C程序变为守护程序(服务器)。该框架不使用任何JNI -rather java套接字 - 并且应用程序可能需要继续使用套接字的JNI实现(还没有为.apk尝试java套接字)。这已经过测试可行。
2 /框架和应用程序都调用C程序,有点像库。这意味着-IMO-我们要么从java中“执行”(坏),要么在JNI中实现整个代码(现在是2000多行)。
我的偏见 - 对此的看法: 1 /
+ it's proven to work
+ there is a clear separation between low-level and high-level
+ there might be no JNI usage
+ because I use a C daemon, I can simulate the behaviour on x86 (using an environment provided by the manufacturer)
- architecture is somewhat complex
- depending on whether the .apk can use a java socket or not, the framework and the .apk won't use the exact same mechanisms to
interface with the daemon (java socket and JNI C socket)
2 /
+ architecture would be simple (with the whole C in the JNI)
- maintaining is going to be a pain
- it's not simulable, development has to either be on target or on emulator
- the android FW has to use JNI (couldn't make this work so far because of a libc error)
- useless use of JNI (from what I understand, should be used for heavy calculations/low-level interfacing)
Android的正确方法是什么?一种方法看起来比它的方法更优雅吗?